Download the PHP package splitstack/laravel-conveyor without Composer
On this page you can find all versions of the php package splitstack/laravel-conveyor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-conveyor
splitstack/laravel-conveyor
A lightweight saga pattern for Laravel. Brings explicit compensation contracts to Actions, UseCases, and Sequences.
The Problem
When a sequence sequences DB writes alongside external API calls, no single transaction can provide consistency. DB transactions are local; Stripe charges, S3 puts, and webhook calls are not rollbackable. Standard try/catch leaves the compensation logic scattered and implicit.
This package makes it structural.
Core Concepts
DB rollback is owned by the transaction. undo() is for everything else (API calls, S3, webhooks). An Action whose only mutations are DB writes declares an empty undo() which is the explicit answer to the compensation question.
Installation
The service provider is auto-discovered.
Actions
UseCases
A UseCase is a CompensableScope over its Actions and is itself Compensable so a parent pipeline can undo it, cascading compensation down to every Action it ran.
step()executes an Action and registers it for potential compensation.- Domain events recorded inside
executeWithEvents()are dispatched only after the outermost transaction commits but never on failure. undo()is inherited: it replays all registered Action undos in reverse.
SequencePayload
A typed DTO that travels through the pipeline. Constructor-promoted properties for entry-time data; the inherited set/get/has bag for values produced mid-pipeline.
Steps
A Step adapts any existing class, including code that is closed for modification, into the pipeline. It extracts what the callee needs from the payload, calls it, and declares compensation as its own behavior.
Steps declare requires(): array to skip themselves when payload keys are absent:
Sequences
Extend Sequence and call steps() / skippable() / run(). Call transacts() to wrap the whole sequence in one DB transaction (inner UseCase transactions become savepoints). Without it, each step commits on its own and only external state is compensated on failure.
On failure at any step:
- DB: the outer transaction rolls back all writes from all steps, including released savepoints.
- External state:
undo()cascades in reverse through every completed step.
Delegation (async steps)
Some steps don't need to run in-band: a webhook notification, a downstream sync, anything that can happen after the request commits. Mark them with delegate() and they are dispatched to the queue instead of invoked inline.
This is an unopinionated option, not a policy. What the package does and does not do:
- Dispatch, not run. A delegated step is dispatched via
ConveyorStepJob, which carries the step's class name and the payload. On the worker the step is rebuilt from the container (collaborators re-injected, never serialized). It is not tracked on the parent's rewind stack. - Self-compensation. When the job exhausts its retries, its
failed()hook calls the step's ownrewind(). Delegated steps compensate themselves; the parent sequence's cascade does not reach them. - Retry policy. If the step declares
getRetryConfig(), it maps onto the job:tries→$tries,backoff→$backoff,timeout→$timeout. No config means a single attempt. afterCommit(default on). By default dispatch waits for the surrounding transaction to commit, so inline /transacts()writes land before the worker reads them. Passdelegate($step, afterCommit: false)to dispatch immediately — your call.- Ordering. Multiple
delegate()calls form a single chain in declaration order. If a terminal step depends on delegated work finishing, delegate it too as the chain tail (or move it into a chain callback). - Serialization is yours. There is no
SerializablePayloadcontract and no runtime guard. If the payload doesn't serialize, Laravel throws — that's the signal. Idempotency and payload independence are the developer's responsibility.
Domain events are the alternative when you want post-commit side effects without the queue. The package holds no opinion on which you reach for.
Graceful abort
Throw SequenceAbortedException from any step to stop cleanly. Completed work commits, events fire, no compensation runs.
Compensation failure
If undo() itself throws, the cascade continues (no step is abandoned) and the failure is reported:
Default behavior when no hook is set: Log::error.
Per-step retry
Actions and UseCases opt into retry by overriding getRetryConfig(). isUnrecoverableError() must then be implemented: it is the explicit declaration that some failures should not be retried.
When retries are exhausted, the onStepFailed hook fires before compensation begins. The FailedStep object carries everything needed to dispatch a Laravel queue job:
Nested transaction behavior
| Context | DB::transaction() behavior |
|---|---|
| Action inside a UseCase | savepoint (released on UseCase "commit") |
| UseCase inside a Sequence | savepoint (rolled back if pipeline rolls back) |
| UseCase called standalone | outermost transaction, commits immediately |
DB::afterCommit defers to the outermost transaction in all cases. Events recorded inside a UseCase nested in a pipeline fire only when the pipeline itself commits.
Diagrams
Compensation hierarchy
Both Sequence and TransactionalBoundary use the ManagesUndoStack trait, so each has its own undo stack. On failure, each layer calls compensate() on what it directly tracked: the pipeline compensates its Steps, each UseCase compensates its own Actions (and nested UseCases cascade further).
When Action C (inside Step 2 / UseCase 2) fails, the unwinding is:
UseCase 2catches →DB::rollBack()to savepoint →compensate()→Action C.undo()(external side-effects only)- Exception bubbles to
Sequence→DB::rollBack()real transaction (wipes all DB writes) →compensate()→Step 1.undo()(Step 2 never completed, so it was never tracked)
Execution sequence
Sequence and TransactionalBoundary both call DB::beginTransaction() via Transactioner. Laravel handles nesting with savepoints: the first call opens a real transaction; nested calls create a savepoint. The pipeline holds the outer transaction; each UseCase inside runs on a savepoint. On failure, the UseCase rolls back to its savepoint and calls compensate() on its actions, then the exception bubbles up and the pipeline rolls back the real transaction and calls compensate() on completed Steps.
Scope of this package
This package provides best-effort, in-process compensation with explicit contracts. It is not durable execution, if the process crashes between an external mutation and its undo(), no compensation runs. For guaranteed compensation across process restarts, consider Temporal.io or a durable sequence engine.
The onStepFailed / onCompensationFailed hooks are the extension points for plugging in queue-backed retry.
All versions of laravel-conveyor with dependencies
illuminate/bus Version ^10.0|^11.0|^12.0|^13.0
illuminate/contracts Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/events Version ^10.0|^11.0|^12.0|^13.0
illuminate/pipeline Version ^10.0|^11.0|^12.0|^13.0
illuminate/queue Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0