Skip to main content
Durable Workflow relies on Laravel’s queue system to execute workflows and activities asynchronously. Proper queue configuration is essential for reliable workflow execution.

Laravel Queue Dependency

Durable Workflow is built on top of Laravel’s queue infrastructure, which is included in the Laravel framework:
"require": {
  "php": "^8.1",
  "laravel/framework": "^9.0|^10.0|^11.0|^12.0|^13.0"
}

Queue Connection

Configure your queue connection in config/queue.php. Durable Workflow supports any Laravel queue driver:
  • Database - Simple, no additional infrastructure
  • Redis - High performance, recommended for production
  • Amazon SQS - Managed queue service
  • Beanstalkd - Specialized queue server

Database Driver Example

// config/queue.php
'connections' => [
    'database' => [
        'driver' => 'database',
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],
],

Redis Driver Example

// config/queue.php
'connections' => [
    'redis' => [
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => env('REDIS_QUEUE', 'default'),
        'retry_after' => 90,
        'block_for' => null,
    ],
],

Per-Workflow Queue Configuration

You can specify different queue connections and queues for individual workflows using WorkflowOptions:
use Workflow\WorkflowOptions;

$options = new WorkflowOptions(
    connection: 'redis',
    queue: 'workflows'
);

Workflow::start(MyWorkflow::class, ['data'], $options);

Using the set() Method

$options = WorkflowOptions::set([
    'connection' => 'redis',
    'queue' => 'high-priority'
]);

Workflow::start(ImportWorkflow::class, [$file], $options);

Queue Workers

Run queue workers to process workflow jobs:

Single Worker

php artisan queue:work

Specific Connection

php artisan queue:work redis

Specific Queue

php artisan queue:work --queue=workflows

Multiple Queues with Priority

php artisan queue:work --queue=high-priority,workflows,default

Production Considerations

Supervisor Configuration

Use Supervisor to keep queue workers running in production:
[program:workflow-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/artisan queue:work redis --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
numprocs=4
redirect_stderr=true
stdout_logfile=/path/to/logs/worker.log
stopwaitsecs=3600

Horizon (Redis Only)

For Redis-based queues, consider using Laravel Horizon for advanced queue monitoring:
composer require laravel/horizon
php artisan horizon:install
php artisan horizon

Queue Configuration Best Practices

Redis provides better performance and reliability than the database driver for production workloads.
Use dedicated queues for workflows to isolate them from other application jobs:
WorkflowOptions::set(['queue' => 'workflows'])
Set appropriate retry_after values based on your workflow execution times:
'retry_after' => 300, // 5 minutes
Use Laravel Horizon or custom monitoring to track queue depth and failed jobs.

Failed Jobs

Configure failed job handling in config/queue.php:
'failed' => [
    'driver' => env('QUEUE_FAILED_DRIVER', 'database'),
    'database' => env('DB_CONNECTION', 'mysql'),
    'table' => 'failed_jobs',
],
View failed jobs:
php artisan queue:failed
Retry failed jobs:
php artisan queue:retry all

WorkflowOptions Reference

connection
string
default:"null"
The queue connection to use for this workflow. If null, uses the default connection.
queue
string
default:"null"
The queue name to use for this workflow. If null, uses the default queue.

Build docs developers (and LLMs) love