Alarmist.Engine (alarmist v0.2.2)

View Source

Synthetic alarm processing engine

This module is intended for users extending the Alarmist DSL.

Summary

Types

t()
  • :registered_rules - map of alarm_id to its compiled rules
  • :alarm_id_to_rules - map of alarm_id to the list of rules to evaluate (inverse of :registered_rules)
  • :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

t()

@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(),
  registered_rules: %{
    required(Alarmist.alarm_id()) => Alarmist.compiled_rules()
  },
  states: map(),
  timers: map()
}
  • :registered_rules - map of alarm_id to its compiled rules
  • :alarm_id_to_rules - map of alarm_id to the list of rules to evaluate (inverse of :registered_rules)
  • :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

add_synthetic_alarm(engine, alarm_id, compiled_rules)

@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.

cache_put(engine, alarm_id, alarm_state, description)

Cache alarm state and record the change

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

clear_alarm(engine, alarm_id)

@spec clear_alarm(t(), Alarmist.alarm_id()) :: t()

commit_side_effects(engine)

@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.

handle_timeout(engine, expiry_alarm_id, value, timer_id)

@spec handle_timeout(t(), Alarmist.alarm_id(), :set | :clear, reference()) :: t()

init(lookup_fun)

@spec init(alarm_lookup_fun()) :: t()

remove_synthetic_alarm(engine, synthetic_alarm_id)

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

Remove all of the rules associated with the specified id

set_alarm(engine, alarm_id, description)

@spec set_alarm(t(), Alarmist.alarm_id(), Alarmist.alarm_description()) :: t()

Report that an alarm_id has changed state

synthetic_alarm_ids(engine)

@spec synthetic_alarm_ids(t()) :: [Alarmist.alarm_id()]