Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Jobpipeline Laravel Package

stancl/jobpipeline

Convert an event into a sequence of jobs. JobPipeline turns any series of Laravel jobs into an event listener, letting you send data from the event and run the pipeline sync or queued, optionally on a specific queue.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Event-Driven Workflows: Perfectly aligns with Laravel’s event system, enabling declarative, modular job sequences without custom orchestration logic. Reduces boilerplate for chaining jobs (e.g., CreateDatabase → MigrateDatabase → SeedDatabase).
  • Decoupled Design: Jobs are independent units that can be updated or replaced without modifying event listeners, adhering to SOLID principles and DDD boundaries.
  • Atomicity Control: Built-in pipeline cancellation (via return false) ensures idempotency for critical workflows (e.g., tenant provisioning).
  • Laravel-Native: Leverages Laravel’s queue system, events, and jobs, avoiding external dependencies. Ideal for teams prioritizing monolithic Laravel architectures or microservices with shared event buses.

Integration Feasibility

  • Minimal Setup: Requires zero new infrastructure—integrates via EventServiceProvider or Event::listen(), with no database migrations or schema changes.
  • Job Compatibility: Works with any Laravel job (including custom jobs with dependencies) and supports closure-based payload mapping for dynamic inputs.
  • Queue System Agnostic: Compatible with database, Redis, SQS, etc., via Laravel’s queue drivers. No vendor lock-in.
  • Event System Integration: Seamlessly replaces synchronous event handlers with async pipelines, reducing request timeouts and improving scalability.

Technical Risk

  • Error Handling: Pipeline failures stop subsequent jobs by default (configurable). Requires custom retry logic for transient failures (e.g., API timeouts). Mitigate by:
    • Wrapping jobs in try-catch blocks.
    • Using Laravel’s failed job system (config('queue.fail_on_timeout')).
    • Pairing with queue supervisors (e.g., spatie/laravel-queue-supervisor).
  • State Management: Jobs cannot share state between steps (e.g., no Job B reading Job A’s output without explicit event dispatching). Workaround:
    • Use shared storage (Redis, database) or event broadcasting.
    • Chain jobs via intermediate events (e.g., DatabaseCreatedMigrateDatabaseJob).
  • Testing Complexity: Pipeline behavior (e.g., cancellation, queuing) requires mocking events and queues. Use:
    • Laravel’s fake() for events/queues.
    • Unit tests for individual jobs + integration tests for pipelines.
  • Performance Overhead: Queued pipelines introduce latency and queue bloat if not monitored. Mitigate with:
    • Queue batching (e.g., batch() in Laravel 10+).
    • Horizontal scaling (multiple queue workers).
    • Monitoring (Laravel Horizon, Blackfire).

Key Questions

  1. Workflow Complexity:
    • Are pipelines linear (A → B → C) or do they require branching/conditional logic? If the latter, consider Temporal or custom event dispatching.
    • Do jobs need shared state between steps? If yes, design a shared data layer (e.g., Redis, database).
  2. Error Recovery:
    • How should failures be handled? Retry, compensating actions, or manual review? Align with Laravel’s failed job system or third-party packages.
  3. Scaling Requirements:
    • Will pipelines block requests if synchronous? Use queued execution by default (JobPipeline::$shouldBeQueuedByDefault = true).
    • Are there SLA requirements for pipeline completion? Monitor with Laravel Horizon or Prometheus.
  4. Observability:
    • Do you need audit logs or metrics for pipelines? Extend with Laravel Telescope or custom logging middleware.
  5. Team Adoption:
    • Is the team familiar with Laravel queues/events? Provide training or internal docs for JobPipeline patterns.
    • Are there legacy synchronous handlers to migrate? Prioritize high-impact workflows (e.g., tenant onboarding) first.

Integration Approach

Stack Fit

  • Laravel 10+: Fully compatible with Laravel 10/11/12/13 (tested up to v2.0.0-rc7). No breaking changes expected for minor Laravel updates.
  • PHP 8.1+: Supports PHP 8.1–8.4 (explicit type hints, nullable returns). Avoids deprecated features.
  • Queue Drivers: Works with database, Redis, SQS, etc.. No driver-specific logic.
  • Event System: Integrates with Laravel’s event dispatching, including local/remote events (via Illuminate\Broadcasting).
  • Job Dependencies: Supports jobs with constructor injection (e.g., repositories, services) as long as dependencies are resolvable by Laravel’s container.

Migration Path

  1. Assessment Phase:
    • Audit existing event listeners for synchronous job dispatching (e.g., Event::listen(fn() => MyJob::dispatch())).
    • Identify candidate pipelines (e.g., multi-step workflows like tenant creation).
  2. Pilot Implementation:
    • Replace one complex listener with JobPipeline (e.g., TenantCreated[CreateDB, MigrateDB, SeedDB]).
    • Test error handling (e.g., simulate a failed CreateDB job).
  3. Incremental Rollout:
    • Migrate low-risk workflows first (e.g., non-critical batch jobs).
    • Gradually replace synchronous handlers with queued pipelines.
  4. Deprecation:
    • Phase out custom queue dispatching in listeners (e.g., MyJob::dispatch()).
    • Use JobPipeline::toListener() for clean listener registration.

Compatibility

  • Backward Compatibility: Maintains 1.x API alongside 2.x. No forced upgrades.
  • Custom Jobs: Works with any Laravel job, including those using:
    • Job middleware (e.g., Retry, Timeout).
    • Custom handlers (e.g., handle() with dependencies).
  • Third-Party Jobs: Compatible with jobs from packages like spatie/laravel-activitylog, laravel-breeze, etc.
  • Event Broadcasting: Pipelines can dispatch events between jobs if needed (e.g., JobA emits JobBTriggered).

Sequencing

  1. Design Phase:
    • Model workflows as pipelines: Group jobs by logical boundaries (e.g., "provisioning," "order processing").
    • Define payload mapping: Use send() to transform events into job inputs (e.g., TenantCreatedtenant object).
  2. Implementation:
    • Register pipelines in EventServiceProvider:
      protected $listen = [
          TenantCreated::class => [
              JobPipeline::make([CreateDB::class, MigrateDB::class])
                  ->send(fn($event) => $event->tenant)
                  ->shouldBeQueued(true)
                  ->toListener(),
          ],
      ];
      
    • For dynamic pipelines, use Event::listen() in a service provider or bootstraper.
  3. Testing:
    • Unit tests: Mock events and verify job execution order.
    • Integration tests: Use Queue::fake() to test queued pipelines.
    • Chaos testing: Simulate failures (e.g., CreateDB throws an exception).
  4. Deployment:
    • Feature flag pipelines for gradual rollout.
    • Monitor queue backlogs (Laravel Horizon) during migration.

Operational Impact

Maintenance

  • Low Overhead: No new services or infrastructure required. Maintenance aligns with Laravel’s core.
  • Dependency Updates:
    • Monitor Laravel and PHP versions (package supports up to Laravel 13).
    • Update stancl/jobpipeline when breaking changes are introduced (e.g., PHP 8.5 compatibility).
  • Debugging:
    • Failed jobs appear in Laravel’s failed_jobs table. Use php artisan queue:failed-table to inspect.
    • Pipeline logs: Extend with JobPipeline::make()->log() or Laravel’s Log::channel().
  • Documentation:
    • Maintain internal docs for:
      • Pipeline registration patterns.
      • Error handling strategies (e.g., retries, dead-letter queues).
      • Payload mapping examples.

Support

  • Troubleshooting:
    • Common issues:
      • Jobs not executing: Check queue workers (php artisan queue:work), queue connections, and event listeners.
      • Pipeline cancellation: Verify return false logic in jobs.
      • Payload mismatches: Debug send() closure with dd($event->data).
    • **Tools
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
boundwize/jsonrecast
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata