View Source Alarmist.Engine (alarmist v0.1.2)

Synthetic alarm processing engine

Summary

Types

t()
  • :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()}
  | {:clear, Alarmist.alarm_id()}
  | {:set_description, Alarmist.alarm_id(), any()}
@type alarm_lookup_fun() :: (Alarmist.alarm_id() -> Alarmist.alarm_state())
@type t() :: %Alarmist.Engine{
  actions_r: list(),
  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

Link to this function

add_synthetic_alarm(engine, alarm_id, compiled_rules)

View Source
@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

Link to this function

cache_put(engine, alarm_id, alarm_state, description)

View Source
@spec cache_put(t(), Alarmist.alarm_id(), Alarmist.alarm_state(), any()) :: t()

Cache alarm state and record the change

IMPORTANT: Rules are evaluated on the next call to run/2 if there was a change.

Link to this function

clear_alarm(engine, alarm_id)

View Source
@spec clear_alarm(t(), Alarmist.alarm_id()) :: t()
Link to this function

commit_side_effects(engine)

View Source
@spec commit_side_effects(t()) :: {t(), [action()]}

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.

Link to this function

handle_timeout(engine, expiry_alarm_id, value, timer_id)

View Source
@spec handle_timeout(t(), Alarmist.alarm_id(), :set | :clear, reference()) :: t()
@spec init(alarm_lookup_fun()) :: t()
Link to this function

remove_synthetic_alarm(engine, synthetic_alarm_id)

View Source
@spec remove_synthetic_alarm(t(), Alarmist.alarm_id()) :: t()

Remove all of the rules associated with the specified id

Link to this function

set_alarm(engine, alarm_id, description)

View Source
@spec set_alarm(t(), Alarmist.alarm_id(), any()) :: t()

Report that an alarm_id has changed state