Chronicle.Registration.RetryPolicy (cratis_chronicle v3.16.1)

Copy Markdown View Source

How registration with the kernel is retried: capped exponential backoff with jitter, a maximum number of attempts, and a distinction between failures worth retrying and failures that will never succeed. Mirrors the .NET client's RegistrationRetryOptions / RegistrationBackoff.

Configure it with the :registration option of Chronicle.Client:

{Chronicle.Client,
 registration: [initial_delay: 1_000, max_delay: 5_000, jitter: 0.2, max_attempts: 10]}
  • :initial_delay - the delay after the first failure in milliseconds (default 5_000)
  • :max_delay - the cap of the exponential growth (default 5_000, so by default the delay stays fixed at :initial_delay, as it always has; raise it to get growth)
  • :multiplier - growth factor between attempts (default 2)
  • :jitter - fraction of the delay randomly added or removed, 0.0 to 1.0 (default 0.0)
  • :max_attempts - give up after this many failed attempts (default :infinity)

A registration the kernel rejects as invalid (a validation failure, an invalid argument) is not retried: repeating it cannot change the answer. It is reported as failed immediately.

Summary

Functions

The delay in milliseconds before attempt number failed_attempts + 1.

Builds a policy from :registration options.

Whether another attempt should be made after failed_attempts failures with reason.

Whether a failure could succeed if repeated.

Types

t()

@type t() :: %Chronicle.Registration.RetryPolicy{
  initial_delay: pos_integer(),
  jitter: float(),
  max_attempts: pos_integer() | :infinity,
  max_delay: pos_integer(),
  multiplier: number()
}

Functions

delay(policy, failed_attempts, random \\ &:rand.uniform/0)

@spec delay(t(), pos_integer(), (-> float())) :: non_neg_integer()

The delay in milliseconds before attempt number failed_attempts + 1.

random is a function returning a float in [0.0, 1.0), injectable for tests.

new(policy)

@spec new(keyword() | t() | nil) :: t()

Builds a policy from :registration options.

retry?(retry_policy, failed_attempts, reason)

@spec retry?(t(), pos_integer(), term()) :: boolean()

Whether another attempt should be made after failed_attempts failures with reason.

retryable?(arg1)

@spec retryable?(term()) :: boolean()

Whether a failure could succeed if repeated.