adachsoft / task-repository-replication
Durable replication of task repositories to synchronous or asynchronous replicas.
Package info
gitlab.com/a.adach/task-repository-replication
pkg:composer/adachsoft/task-repository-replication
Requires
- php: ^8.3
- adachsoft/collection: ^3.0
- adachsoft/task-contracts: ^3.0
- psr/clock: ^1.0
Requires (Dev)
- adachsoft/php-code-style: ^0.8.0
- adachsoft/task-functional-tests: ^3.1
- adachsoft/task-json-file: ^0.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Task Repository Replication decorates the repository contracts from adachsoft/task-contracts and forwards changes from a primary task data set to one or more replicas. It is intended for applications that need a durable handoff between primary writes and replica updates.
Features
- Synchronous replication during the primary repository operation or asynchronous replication through an explicit worker.
- A durable, file-backed outbox with per-replica progress tracking.
- Decorators for task, comment, attachment metadata, and attachment content contracts.
- Replication status inspection and repository reconciliation.
- Factory-based assembly that keeps application repository implementations behind the task contracts.
Installation
Install the package with Composer:
composer require adachsoft/task-repository-replication
The package requires PHP 8.3 or later. Provide repository implementations compatible with adachsoft/task-contracts and a PSR-20 clock implementation in your application.
Requirements
- PHP 8.3 or later.
- Repository implementations compatible with
adachsoft/task-contracts. - A PSR-20 clock implementation.
Usage
Assemble the replication runtime with the primary repositories, configured replicas, a writable outbox, and a clock. Use the runtime's repository decorators in place of the primary repositories. See the integration example for the complete setup and delivery workflow.
Integration
Create a RepositorySetDto for the primary storage and one for each replica. Configure each replica with a unique ReplicaName and a delivery mode, then assemble the runtime with a writable directory for the file-backed outbox:
$outbox = FileOutboxFactory::create('/var/lib/my-app/replication-outbox');
$runtime = RepositoryReplicationFactory::create(
$primaryRepositories,
new ReplicaConfigurationCollection([
new ReplicaConfigurationDto(
new ReplicaName('reporting'),
ReplicationModeEnum::ASYNC,
$reportingRepositories,
),
]),
$outbox,
$clock,
);
Use the runtime's tasks, comments, attachments, and attachmentContent properties in place of the corresponding primary repositories. For asynchronous delivery, schedule calls to $runtime->worker->runUntilIdle($replicaName) and monitor progress through $runtime->status->getAll(). The reconciler accepts a replica name and can run in dry-run mode before applying repairs. Synchronous replicas are applied as part of the primary repository operation. The runtime also exposes $runtime->reconciler for repairing replica state.
See the integration example for the complete assembly flow and operational notes.