Oihana PHP Arango

RetryPolicy

Read onlyYes

Retry policy for the ArangoDB HTTP transport.

Encapsulates two decisions:

  • whether a given failed attempt should be retried (based on ArangoException::isSafeToRetry() and the per-policy attempt budget),
  • how long to wait before the next attempt (capped exponential back-off).

The default policy retries up to three times with a delay sequence of 100 ms, 200 ms, 400 ms, … capped at 5 000 ms.

Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

DEFAULT_BASE_DELAY_MS  : int = 100
Default base delay between two attempts, in milliseconds.
DEFAULT_MAX_ATTEMPTS  : int = 3
Default maximum number of attempts (initial attempt + retries).
DEFAULT_MAX_DELAY_MS  : int = 5000
Default upper bound for the back-off delay, in milliseconds.

Properties

$baseDelayMs  : int
$maxAttempts  : int
$maxDelayMs  : int

Methods

__construct()  : mixed
delayMs()  : int
Computes the delay (in milliseconds) to wait before attempt number `$attempt`.
shouldRetry()  : bool
Decides whether a failed attempt should be retried.

Constants

DEFAULT_BASE_DELAY_MS

Default base delay between two attempts, in milliseconds.

public int DEFAULT_BASE_DELAY_MS = 100

DEFAULT_MAX_ATTEMPTS

Default maximum number of attempts (initial attempt + retries).

public int DEFAULT_MAX_ATTEMPTS = 3

DEFAULT_MAX_DELAY_MS

Default upper bound for the back-off delay, in milliseconds.

public int DEFAULT_MAX_DELAY_MS = 5000

Properties

$baseDelayMs

public int $baseDelayMs = self::DEFAULT_BASE_DELAY_MS

$maxAttempts

public int $maxAttempts = self::DEFAULT_MAX_ATTEMPTS

$maxDelayMs

public int $maxDelayMs = self::DEFAULT_MAX_DELAY_MS

Methods

__construct()

public __construct([int $maxAttempts = self::DEFAULT_MAX_ATTEMPTS ][, int $baseDelayMs = self::DEFAULT_BASE_DELAY_MS ][, int $maxDelayMs = self::DEFAULT_MAX_DELAY_MS ]) : mixed
Parameters
$maxAttempts : int = self::DEFAULT_MAX_ATTEMPTS

Maximum number of attempts (1 = no retry).

$baseDelayMs : int = self::DEFAULT_BASE_DELAY_MS

Base delay in milliseconds for the first retry; doubled on each subsequent retry.

$maxDelayMs : int = self::DEFAULT_MAX_DELAY_MS

Upper bound on the delay (the back-off is capped at this value).

delayMs()

Computes the delay (in milliseconds) to wait before attempt number `$attempt`.

public delayMs(int $attempt) : int

The sequence is baseDelayMs * 2^(attempt-1), capped at maxDelayMs. Returns 0 for attempt numbers lower than 1 (defensive).

Parameters
$attempt : int

The attempt number that just failed (1 = first attempt).

Return values
int

Delay in milliseconds.

shouldRetry()

Decides whether a failed attempt should be retried.

public shouldRetry(ArangoException $exception, int $attempt) : bool

A retry is allowed when both conditions are met:

  • the attempt budget is not exhausted ($attempt < $maxAttempts),
  • the exception reports itself as safe to retry.
Parameters
$exception : ArangoException

The exception raised by the failed attempt.

$attempt : int

The attempt number that just failed (1-indexed).

Return values
bool
On this page

Search results