跳到主要内容
版本:1.x

Options

There are various options available when defining your workflows and activities. These options include the number of times a workflow or activity may be attempted before it fails, the connection and queue, and the maximum number of seconds it is allowed to run.

use Workflow\Activity;

class MyActivity extends Activity
{
public $connection = 'default';
public $queue = 'default';

public $tries = 0;
public $timeout = 0;

public function backoff()
{
return [1, 2, 5, 10, 15, 30, 60, 120];
}
}

WorkflowOptions​

You can also set queue options at workflow start time using WorkflowOptions.

use Workflow\WorkflowOptions;
use Workflow\WorkflowStub;

$workflow = WorkflowStub::make(MyWorkflow::class);

$workflow->start(
'arg1',
WorkflowOptions::set([
'connection' => 'redis',
'queue' => 'critical',
])
);

// OR

$workflow->start('arg1', new WorkflowOptions('redis', 'critical'));

WorkflowOptions are consumed by the workflow engine and are not passed as arguments to your workflow execute() method.

These options are persisted with the workflow and used for subsequent workflow/activity dispatching (including replay and continue-as-new behavior).

Connection​

The $connection setting is used to specify which queue connection the workflow or activity should be sent to. By default, the $connection value is not set which will use the default connection. This can be overridden by setting the $connection property on the workflow or activity class.

Queue​

The $queue setting is used to specify which queue the workflow or activity should be added to. By default, the $queue value is not set which uses the default queue for the specified connection. This can be overridden by setting the $queue property on the workflow or activity class.

Retries​

The $tries setting is used to control the number of retries an activity is attempted before it is considered failed. By default, the $tries value is set to 0 which means it will be retried forever. This can be overridden by setting the $tries property on the activity class.

Timeout​

The $timeout setting is used to control the maximum number of seconds an activity is allowed to run before it is killed. By default, the $timeout value is set to 0 seconds which means it can run forever. This can be overridden by setting the $timeout property on the activity class.

Backoff​

The backoff method returns an array of integers corresponding to the current attempt. The default backoff method decays exponentially to 2 minutes. This can be overridden by implementing the backoff method on the activity class.

Legacy workflow overlap delay​

For applications using Workflow\Workflow, set overlapReleaseAfter to a nonnegative integer number of seconds. The default is 0. This setting applies to contended workflow, activity, signal and child-completion queue jobs. It does not change lock expiry or activity exception backoff. Workflow\V2\Workflow uses task claims and does not use this middleware.

use Workflow\WorkflowOptions;
use Workflow\WorkflowStub;

$workflow = WorkflowStub::make(MyLegacyWorkflow::class);
$workflow->start('argument', new WorkflowOptions(overlapReleaseAfter: 5));

WorkflowOptions::set(['overlapReleaseAfter' => 5]) accepts the same setting. The value is persisted with the run and inherited by children and continue-as-new when no explicit WorkflowOptions is supplied. An explicit options object replaces inherited options, including resetting this delay to zero if omitted.

Laravel counts queue reservations as attempts even when middleware releases a job before its handler runs. A positive delay reduces rapid retries but cannot guarantee that a low $tries, --tries, or database queue attempt limit is safe. Choose the delay and retry budget for the expected contention duration.