stancl/jobpipeline
Turn any series of Laravel jobs into an event listener. Build pipelines that pull data from events, run jobs sequentially, and choose sync or queued execution (with optional queue name). Ideal for workflows like tenant setup, migrations, and seeding.
dispatch() calls in event handlers, reducing cognitive load and boilerplate.false cancels subsequent jobs) and error handling (via handleErrors()) mitigate cascading failures in pipelines.CreateDatabase, MigrateDatabase, SeedDatabase jobs.handle() methods in listeners with async jobs.// Before (manual dispatching)
Event::listen(TenantCreated::class, function ($event) {
dispatch(new CreateDatabase($event->tenant));
dispatch(new MigrateDatabase($event->tenant));
dispatch(new SeedDatabase($event->tenant));
});
With:
// After (declarative pipeline)
Event::listen(TenantCreated::class, JobPipeline::make([
CreateDatabase::class,
MigrateDatabase::class,
SeedDatabase::class,
])->send(fn ($event) => $event->tenant)->toListener());
shouldBeQueued('queue-name').shouldBeQueued(true)).send() closure failures) are not automatically retried. Mitigation: Pair with Laravel Horizon or implement custom retry logic in jobs.ShouldQueue + retryAfter() or external tools.fake() for events and queue() for jobs.$shouldBeQueuedByDefault = true) to avoid blocking requests?timeout() or split into smaller pipelines.)Event::listen() with pipeline-based handlers.ShouldQueue or non-queued job.EventServiceProvider or dynamically via Event::listen().composer require stancl/jobpipeline.php artisan queue:work).| Phase | Action | Risk/Mitigation |
|---|---|---|
| Assessment | Audit existing event listeners for manual dispatch() calls. |
Low. |
| Pilot | Replace 1–2 simple listeners (e.g., UserRegistered → pipeline). |
Medium. Test performance/behavior. |
| Core Adoption | Migrate critical workflows (e.g., tenant onboarding, orders). | High. Rollback plan for failures. |
| Full Transition | Deprecate manual dispatching in favor of pipelines. | Low. Update docs/code reviews. |
| Optimization | Profile queue performance; adjust shouldBeQueued() defaults. |
Low. |
^8.1 in composer.json for stability.send() (e.g., public function handle($tenant)).ShouldQueue or non-queued jobs.array or JsonSerializable for complex data.EventServiceProvider:
// app/Providers/EventServiceProvider.php
protected $listen = [
TenantCreated::class => [
fn () => JobPipeline::make([
CreateDatabase::class,
MigrateDatabase::class,
])->send(fn ($event) => $event->tenant)->toListener(),
],
];
\Stancl\JobPipeline\JobPipeline::$shouldBeQueuedByDefault = true;
->shouldBeQueued(true, 'high-priority')
JobPipeline::make([...])->handleErrors();
retryAfter() or implement in job classes.$this->fake()->events();
$this->fake()->queues();
EventServiceProvider or dedicated classes).How can I help you explore Laravel packages today?