View Source Alarmist.Engine (alarmist v0.2.0)
Synthetic alarm processing engine
Summary
Types
:alarm_id_to_rules
- map of alarm_id to the list of rules to run:cache
- temporary cache for alarm status while processing rules:changed_alarm_id
- list of alarm_ids that have changed values:timers
- map of alarm_id to pending timer:actions_r
- list of pending side effects in reverse (engine processing is side-effect free by design so someone else has to do the dirty work):states
- optional state that can be kept on a per-alarm_id basis:lookup_fun
- function for looking up alarm state
Functions
Create and add a synthetic alarm based on the rule specification
Cache alarm state and record the change
Commit all side effects from previous operations
Remove all of the rules associated with the specified id
Report that an alarm_id has changed state
Types
@type action() :: {:set, Alarmist.alarm_id(), Alarmist.alarm_description()} | {:clear, Alarmist.alarm_id()} | {:start_timer, Alarmist.alarm_id(), pos_integer(), Alarmist.alarm_state(), reference()} | {:cancel_timer, reference()}
@type alarm_lookup_fun() :: (Alarmist.alarm_id() -> {Alarmist.alarm_state(), Alarmist.alarm_description()})
@type t() :: %Alarmist.Engine{ actions_r: [action()], alarm_id_to_rules: map(), cache: map(), changed_alarm_ids: [Alarmist.alarm_id()], lookup_fun: alarm_lookup_fun(), rules: map(), states: map(), timers: map() }
:alarm_id_to_rules
- map of alarm_id to the list of rules to run:cache
- temporary cache for alarm status while processing rules:changed_alarm_id
- list of alarm_ids that have changed values:timers
- map of alarm_id to pending timer:actions_r
- list of pending side effects in reverse (engine processing is side-effect free by design so someone else has to do the dirty work):states
- optional state that can be kept on a per-alarm_id basis:lookup_fun
- function for looking up alarm state
Functions
@spec add_synthetic_alarm(t(), Alarmist.alarm_id(), Alarmist.compiled_rules()) :: t()
Create and add a synthetic alarm based on the rule specification
The synthetic alarm will be evaluated, so if the synthetic alarm ID already has subscribers, they'll get notified if the alarm is set.
Raises on errors
@spec cache_put( t(), Alarmist.alarm_id(), Alarmist.alarm_state(), Alarmist.alarm_description() ) :: t()
Cache alarm state and record the change
IMPORTANT: Rules are evaluated on the next call to run/2
if there was a change.
@spec clear_alarm(t(), Alarmist.alarm_id()) :: t()
Commit all side effects from previous operations
The caller needs to run all of the side effects before the next call to the engine so state changes may be lost.
@spec handle_timeout(t(), Alarmist.alarm_id(), :set | :clear, reference()) :: t()
@spec init(alarm_lookup_fun()) :: t()
@spec remove_synthetic_alarm(t(), Alarmist.alarm_id()) :: t()
Remove all of the rules associated with the specified id
@spec set_alarm(t(), Alarmist.alarm_id(), Alarmist.alarm_description()) :: t()
Report that an alarm_id has changed state