View Source ExClockBoundClient (ex_clock_bound_client v0.1.0)

The elixir version of aws clock bound client.

Summary

Functions

Returns true if the provided timestamp is after the latest error bound. Otherwise, returns false.

Returns true if the provided timestamp is before the earliest error bound. Otherwise, returns false.

Returns the deviation in nanosecond of the current system time from the chrony server.

Returns the bounds of the current system time +/- the error calculated from chrony.

Execute function and return bounds on execution time.

Types

@type nanosecond() :: non_neg_integer()
@type unix_time_with_unit() ::
  {nanosecond(), :second | :millisecond | :microsecond | :nanosecond}

Functions

@spec after?(DateTime.t() | unix_time_with_unit()) ::
  {:ok, boolean()} | {:error, :clock_bound_server_error | :invalid_datetime}

Returns true if the provided timestamp is after the latest error bound. Otherwise, returns false.

DateTime Format

The datetime argument could be one of :

  • a DateTime struct.
  • a tuple of the form {unix_time, unit}. unix_time is an integer in unit, and unit is one of :second, :millisecond, :microsecond, or :nanosecond.

Examples

iex> ExClockBoundClient.before?(~U[2024-02-01 11:14:57.656524Z])
{:ok, true}
@spec before?(DateTime.t() | unix_time_with_unit()) ::
  {:ok, boolean()} | {:error, :clock_bound_server_error | :invalid_datetime}

Returns true if the provided timestamp is before the earliest error bound. Otherwise, returns false.

DateTime Format

See DateTime Format in after?/1 .

Examples

iex> ExClockBoundClient.before?(~U[2024-02-01 11:14:57.656524Z])
{:ok, true}
@spec deviation() :: {:ok, nanosecond()} | {:error, :clock_bound_server_error}

Returns the deviation in nanosecond of the current system time from the chrony server.

Examples

iex> ExClockBoundClient.deviation()
{:ok, 1314}
@spec now() ::
  {:ok, {earliest_datetime :: DateTime.t(), latest_datetime :: DateTime.t()}}
  | {:error, :clock_bound_server_error}

Returns the bounds of the current system time +/- the error calculated from chrony.

Examples

iex> ExClockBoundClient.now()
{:ok, {~U[2024-02-01 11:14:57.656524Z], ~U[2024-02-01 11:14:57.706487Z]}}
Link to this function

timing(func, opts \\ [exec_timeout: 5000])

View Source

Execute function and return bounds on execution time.

Options

  • exec_timeout - The maximum time in milliseconds to wait for the function to complete. Default is 5000.

Examples

iex> ExClockBoundClient.timing(fn -> :timer.sleep(1000) end)
{:ok, {{~U[2024-02-01 11:14:57.656524Z], ~U[2024-02-01 11:14:57.706487Z]}, {1011, 1033}}}