Constants

TASK_RETRY_NEVER

TASK_RETRY_NEVER

TASK_RETRY_ONCE

TASK_RETRY_ONCE

TASK_RETRY_ALWAYS

TASK_RETRY_ALWAYS

Properties

$retryMap

$retryMap : array

Type

array — Map of errors with retry counts.

$maxDelay

$maxDelay : integer

Type

integer — The max time (in seconds) to wait before a retry.

$delay

$delay : integer

Type

integer — The previous delay from which the next is calculated.

$factor

$factor : integer

Type

integer — The base number for the exponential back off.

$jitter

$jitter : float

Type

float — A random number between -$jitter and $jitter will be added to $factor on each iteration to allow for a better distribution of retries.

$attempts

$attempts : integer

Type

integer — The number of attempts that have been tried so far.

$maxAttempts

$maxAttempts : integer

Type

integer — The max number of attempts allowed.

$name

$name : string

Type

string — The name of the current task (used for logging).

$action

$action : callable

Type

callable — The task to run and possibly retry.

$arguments

$arguments : array

Type

array — The task arguments.

Methods

__construct()

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

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

Throws

\Google_Task_Exception

when misconfigured

canAttempt()

canAttempt() : boolean

Checks if a retry can be attempted.

Returns

boolean

run()

run() : mixed

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

Throws

\Google_Task_Retryable

on failure when no retries are available.

Returns

mixed

attempt()

attempt() : boolean

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.

Returns

boolean

allowedRetries()

allowedRetries(  $code,   $errors = array()) : integer

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

Returns

integer

setRetryMap()

setRetryMap(  $retryMap) 

Parameters

$retryMap

backOff()

backOff() 

Sleeps in accordance to the backoff configurations.

getDelay()

getDelay() : float

Gets the delay (in seconds) for the current backoff period.

Returns

float

getJitter()

getJitter() : float

Gets the current jitter (random number between -$this->jitter and $this->jitter).

Returns

float