X3m System v0.6.0 X3m.System.Scheduller behaviour View Source
This behaviour should be used to schedulle 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 schedulled 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 it's X3m.System.Message.id
is already in memory (and schedulled 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 Schedullers 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 a alarm.
Time when it should be dispatched is set in it's assigns.dispatch_at
as DateTime
.
This callback is invoked when schedulled message is processed.
Link to this section Callbacks
dispatch_timeout(arg1)
View Source (optional)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
in_memory_interval()
View Source (optional)in_memory_interval() :: milliseconds :: pos_integer()
This is optional callback that should return in which interval (in milliseconds) alarms should be loaded.
load_alarms(load_from, load_until, state)
View Sourceload_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 Schedullers 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
.
save_alarm(arg1, aggregate_id, state)
View Sourcesave_alarm(X3m.System.Message.t(), aggregate_id :: String.t(), state :: any()) :: :ok
This callback is invoked when X3m.System.Message
should be saved as a alarm.
Time when it should be dispatched is set in it's assigns.dispatch_at
as DateTime
.
3rd parameter (state) is the one that was set when Scheduller's start_link/1
was
called.
service_responded(arg1, state)
View Sourceservice_responded(X3m.System.Message.t(), state :: any()) :: :ok | {:retry, in_ms :: non_neg_integer(), X3m.System.Message.t()}
This callback is invoked when schedulled message is processed.
It should return either :ok
(and remove from persitance) so message delivery is not retried or
ammount of milliseconds in which delivery will be retried with potentially
modifed X3m.System.Message
. It's assigns
can used to track number of retries for example.