X3m.System.Scheduler behaviour (X3m System v0.7.5) View Source
This behaviour should be used to schedule X3m.System.Message
delivery
at some point in time in the future. Implementation module should persist alarms so when process
is respawned they can be reloaded into memory.
Not all scheduled alarms are kept in memory. They are loaded in bulks
each in_memory_interval/0
milliseconds for next 2 * in_memory_interval/0
milliseconds.
If message with its X3m.System.Message.id
is already in memory (and scheduled for delivery)
it is ignored.
When message is processed, service_responded/2
callback is invoked. It should return either
:ok
or {:retry, in_milliseconds, X3m.System.Message}
if returned message should be redelivered
in specified number of milliseconds.
Link to this section Summary
Callbacks
This optional callback defines timeout for response (in milliseconds). By default response is being waited for 5_000 milliseconds
This is optional callback that should return in which interval (in milliseconds) alarms should be loaded.
Load alarms callback is invoked on Scheduler's init with load_from
as nil
,
and after that it is invoked each in_memory_interval/0
with load_from
set to previous load_until
value and new load_until
will be
load_from = 2 * in_memory_interval/0
.
This callback is invoked when X3m.System.Message
should be saved as an alarm.
Time when it should be dispatched is set in its assigns.dispatch_at
as DateTime
.
This callback is invoked when scheduled message is processed.
Link to this section Callbacks
Specs
dispatch_timeout(X3m.System.Message.t()) :: milliseconds :: pos_integer()
This optional callback defines timeout for response (in milliseconds). By default response is being waited for 5_000 milliseconds
Specs
in_memory_interval() :: milliseconds :: pos_integer()
This is optional callback that should return in which interval (in milliseconds) alarms should be loaded.
Specs
load_alarms( load_from :: nil | DateTime.t(), load_until :: DateTime.t(), state :: any() ) :: {:ok, [X3m.System.Message.t()]} | {:error, term()}
Load alarms callback is invoked on Scheduler's init with load_from
as nil
,
and after that it is invoked each in_memory_interval/0
with load_from
set to previous load_until
value and new load_until
will be
load_from = 2 * in_memory_interval/0
.
Specs
save_alarm(X3m.System.Message.t(), aggregate_id :: String.t(), state :: any()) :: :ok
This callback is invoked when X3m.System.Message
should be saved as an alarm.
Time when it should be dispatched is set in its assigns.dispatch_at
as DateTime
.
3rd parameter (state) is the one that was set when Scheduler's start_link/1
was
called.
Specs
service_responded(X3m.System.Message.t(), state :: any()) :: :ok | {:retry, in_ms :: non_neg_integer(), X3m.System.Message.t()}
This callback is invoked when scheduled message is processed.
It should return either :ok
(and remove from persitance) so message delivery is not retried or
amount of milliseconds in which delivery will be retried with potentially
modifed X3m.System.Message
. Its assigns
can used to track number of retries for example.