# `Chronicle.Registration.RetryPolicy`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/registration/retry_policy.ex#L4)

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.

# `t`

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

# `delay`

```elixir
@spec delay(t(), pos_integer(), (-&gt; 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`

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

Builds a policy from `:registration` options.

# `retry?`

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

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

# `retryable?`

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

Whether a failure could succeed if repeated.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
