Runbox.StateStore.ScheduleUtils (runbox v7.0.1)
Module contains functions to compute savepoint timestamps.
Savepoint timestamps are calculated as multiples of schedule
.
Link to this section Summary
Types
Timestamp defined as unix epoch in milliseconds
Difference between two unix epoch timestamps in milliseconds
Interval (in seconds) between savepoint timestamps.
Functions
Returns next savepoint based on given schedule
and timestamp
.
Returns previous savepoint based on given schedule
and timestamp
.
Returns unreached savepoints based on given schedule
in range of given timestamps (from; to>
Returns count of unreached savepoints.
Link to this section Types
epoch_ms()
@type epoch_ms() :: non_neg_integer()
Timestamp defined as unix epoch in milliseconds
epoch_ms_interval()
@type epoch_ms_interval() :: non_neg_integer()
Difference between two unix epoch timestamps in milliseconds
schedule()
@type schedule() :: epoch_ms_interval() | :none
Interval (in seconds) between savepoint timestamps.
Link to this section Functions
next_savepoint(schedule, timestamp)
Returns next savepoint based on given schedule
and timestamp
.
Next savepoint is calculated as next multiple of schedule
larger or equal to given
timestamp
.
examples
Examples
iex> Runbox.StateStore.ScheduleUtils.next_savepoint(60_000, 0)
60_000
iex> Runbox.StateStore.ScheduleUtils.next_savepoint(60_000, 10_000)
60_000
iex> Runbox.StateStore.ScheduleUtils.next_savepoint(60_000, 60_000)
120_000
previous_savepoint(schedule, timestamp)
Returns previous savepoint based on given schedule
and timestamp
.
Next savepoint is calculated as previous multiple of schedule
lower or equal to given
timestamp
.
examples
Examples
iex> Runbox.StateStore.ScheduleUtils.previous_savepoint(60_000, 30_000)
0
iex> Runbox.StateStore.ScheduleUtils.previous_savepoint(60_000, 60_000)
60_000
iex> Runbox.StateStore.ScheduleUtils.previous_savepoint(60_000, 90_000)
60_000
iex> Runbox.StateStore.ScheduleUtils.previous_savepoint(60_000, 120_000)
120_000
iex> Runbox.StateStore.ScheduleUtils.previous_savepoint(60_000, 150_000)
120_000
unreached_savepoints(schedule, from, to)
Returns unreached savepoints based on given schedule
in range of given timestamps (from; to>
examples
Examples
iex> Runbox.StateStore.ScheduleUtils.unreached_savepoints(60_000, 0, 120_000)
[60_000, 120_000]
iex> Runbox.StateStore.ScheduleUtils.unreached_savepoints(60_000, 60_000, 120_000)
[120_000]
iex> Runbox.StateStore.ScheduleUtils.unreached_savepoints(60_000, 60_000, 180_000)
[120_000, 180_000]
unreached_savepoints_count(schedule, from, to)
Returns count of unreached savepoints.
examples
Examples
iex> Runbox.StateStore.ScheduleUtils.unreached_savepoints_count(60_000, 0, 120_000)
2
iex> Runbox.StateStore.ScheduleUtils.unreached_savepoints_count(60_000, 60_000, 120_000)
1
iex> Runbox.StateStore.ScheduleUtils.unreached_savepoints_count(1, 0, 120_000)
120_000