- How do I convert a series of Laravel jobs into an event listener using stancl/jobpipeline?
- Use `JobPipeline::make([Job1::class, Job2::class])` to define your job sequence, then chain `.send()` to map event data to job inputs. Register the pipeline as a listener in `EventServiceProvider::$listen` or via `Event::listen()`. Example: `JobPipeline::make([CreateDatabase::class, MigrateDatabase::class])->send(fn($event) => $event->tenant).`
- Does stancl/jobpipeline support Laravel 13? What are the version requirements?
- Yes, stancl/jobpipeline supports Laravel 11–13. Check the package’s `composer.json` for exact version constraints, but it’s designed to work across these releases without framework modifications. Always verify compatibility with your Laravel version.
- Can I queue individual jobs in a pipeline to different queues?
- No, the entire pipeline is queued to a single queue (specified via `shouldBeQueued(true, 'queue-name')`). However, you can use conditional logic in the `send()` closure to dynamically adjust job inputs or leverage job-specific queue logic inside each job’s `handle()` method.
- How do I handle failures in a job pipeline? Does it retry failed jobs?
- Pipelines short-circuit on job failure (return `false` to stop execution). Use Laravel’s `failed_jobs` table for retries or implement compensation logic in a separate job. For critical workflows, combine with `shouldQueue()` and monitor the `failed_jobs` table.
- Is there a way to test job pipelines without hitting the queue?
- Yes, pipelines run synchronously by default. Test them directly by triggering the event in your tests: `Bus::dispatch(new TenantCreated($tenant));`. Mock the jobs or use `JobPipeline::make()->toListener()` to isolate pipeline logic for unit tests.
- Can I use stancl/jobpipeline for conditional workflows (e.g., skip a job based on user role)?
- Not natively—pipelines execute jobs sequentially without branching. For conditional logic, use the `send()` closure to filter data or dynamically inject jobs via `array_merge()` before creating the pipeline. Example: `JobPipeline::make(array_merge([$baseJobs], $conditionalJobs))`.
- How does stancl/jobpipeline compare to spatie/laravel-sagas for workflows?
- stancl/jobpipeline is simpler and Laravel-native, ideal for linear, sequential workflows (e.g., tenant provisioning). spatie/laravel-sagas offers more advanced features like compensation transactions and parallel steps but adds complexity. Choose stancl/jobpipeline for lightweight, event-driven pipelines.
- Will job pipelines work with custom job dependencies (e.g., jobs that require other jobs to complete)?
- Yes, pipelines enforce sequential execution, so each job depends on the previous one’s success. If a job fails, the pipeline stops. For complex dependencies, ensure jobs are idempotent or use the `send()` closure to pass intermediate results explicitly.
- Can I log intermediate steps in a job pipeline for debugging?
- No direct logging method exists, but you can inject logging into individual jobs or use Laravel’s logging facade inside the `send()` closure. For observability, consider wrapping the pipeline in middleware or using `JobPipeline::make()->withMiddleware()` to add custom logic.
- How do I migrate from monolithic jobs to job pipelines in an existing Laravel app?
- Start by auditing jobs for sequential dependencies. Replace one monolithic job with a pipeline (e.g., `JobPipeline::make([Step1::class, Step2::class])`), then gradually refactor others. Use feature flags to toggle between old and new workflows during migration. Test pipelines in staging first.