Limen.Signal.Asn.Schedule (limen v0.2.1)

Copy Markdown View Source

When the ASN loader checks for new data, as pure functions of the time.

A check is due :every milliseconds after the last successful one, plus a random delay of up to :jitter times :every, so nodes that started together do not check together. The last successful check is the time the data file was last confirmed current, so restarting a node does not postpone its next check. A check that is already overdue runs after the random delay alone.

With :window, checks only run inside the given times of day (UTC): a check due outside them moves to a random time inside the next window, so nodes spread over it rather than all starting as it opens.

A failed check is retried after :retry milliseconds, doubling with every consecutive failure up to :every; a postponed one after :retry. Both also respect the window.

Every function returns the time of the next check, in milliseconds since the epoch. random arguments are floats in [0, 1), drawn by the caller, so these functions are deterministic.

Summary

Types

The :refresh options of the :asn configuration, see Limen.Config.

Functions

Whether the time at (milliseconds since the epoch) is inside one of windows. Always true without windows.

When to check after a successful check at checked_at.

When to retry after failures consecutive failed checks.

When to try a postponed check again.

Types

config()

@type config() :: %{
  :every => pos_integer(),
  :jitter => number(),
  :window => [{Time.t(), Time.t()}] | nil,
  :retry => pos_integer(),
  optional(:max_utilization) => number() | nil,
  optional(:max_memory) => pos_integer() | nil,
  optional(:timeout) => pos_integer()
}

The :refresh options of the :asn configuration, see Limen.Config.

Functions

in_window?(at, windows)

@spec in_window?(integer(), [{Time.t(), Time.t()}] | nil) :: boolean()

Whether the time at (milliseconds since the epoch) is inside one of windows. Always true without windows.

next_check(now, checked_at, config, random)

@spec next_check(integer(), integer() | nil, config(), float()) :: integer()

When to check after a successful check at checked_at.

With no successful check yet (nil), there is no data to wait with, so the check is due now, whatever the window.

retry_failed(now, failures, config, random)

@spec retry_failed(integer(), pos_integer(), config(), float()) :: integer()

When to retry after failures consecutive failed checks.

retry_postponed(now, config, random)

@spec retry_postponed(integer(), config(), float()) :: integer()

When to try a postponed check again.