class Runner (View source)

A task runner with exponential backoff support.

Constants

TASK_RETRY_NEVER

TASK_RETRY_ONCE

TASK_RETRY_ALWAYS

Properties

protected array $retryMap

Methods

__construct(array $config, string $name, callable $action, array $arguments = [])

Creates a new task runner with exponential backoff support.

bool
canAttempt()

Checks if a retry can be attempted.

mixed
run()

Runs the task and (if applicable) automatically retries when errors occur.

bool
attempt()

Runs a task once, if possible. This is useful for bypassing the run() loop.

int
allowedRetries($code, $errors = [])

Gets the number of times the associated task can be retried.

setRetryMap($retryMap)

No description

Details

__construct(array $config, string $name, callable $action, array $arguments = [])

Creates a new task runner with exponential backoff support.

Parameters

array $config

The task runner config

string $name

The name of the current task (used for logging)

callable $action

The task to run and possibly retry

array $arguments

The task arguments

Exceptions

Exception

bool canAttempt()

Checks if a retry can be attempted.

Return Value

bool

mixed run()

Runs the task and (if applicable) automatically retries when errors occur.

Return Value

mixed

Exceptions

Exception

bool attempt()

Runs a task once, if possible. This is useful for bypassing the run() loop.

NOTE: If this is not the first attempt, this function will sleep in accordance to the backoff configurations before running the task.

Return Value

bool

int allowedRetries($code, $errors = [])

Gets the number of times the associated task can be retried.

NOTE: -1 is returned if the task can be retried indefinitely

Parameters

$code
$errors

Return Value

int

setRetryMap($retryMap)

No description

Parameters

$retryMap