Skip to main content

Module engine

Module engine 

Source
Expand description

Matching and running rules against events, with loop protection.

  • Events of kind rule.* (the engine’s own bookkeeping) never trigger rules.
  • A rule already running in the current chain is not started again.
  • Chains stop at MAX_DEPTH rules; one outermost event starts at most MAX_RUNS runs.
  • Blocked runs are reported to Host::blocked with the reason.

The application supplies the rules, the events’ fields, what “related” means, and what a then-action does, through Host. Whether someone may create, change or run a rule is decided by the application before it gets here.

Structs§

Check
How a rule fares against one event (a dry run).
CondCheck
Run
The run of one rule, handed to Host::finish_run.
RunResult
The outcome of one run.
Runtime
The chain of rules running now (outermost first) and the runs left for the outermost event. Owned by the application (one per store or session) and handed out by Host::runtime.

Constants§

MAX_DEPTH
Most rules in one chain (a rule whose action triggers a rule whose action triggers …).
MAX_RUNS
Most rule runs started by one outermost event.
SCHEDULE
The event kind a scheduled rule runs on. With a rule param naming a rule, only that rule (if it has a schedule or listens to schedule) reacts.

Traits§

Event
Something that happened, as the engine sees it.
Host
What the engine needs from the application.
Rule
A stored rule, as the engine sees it.

Functions§

brief
One line about a rule: on import → 2 actions, every 6h, on import → 1 action (off).
check
Does the rule apply to the event, and why (not)? Does not look at enabled.
dispatch
Run every enabled rule that matches the event (call after each event is recorded). Returns how many runs started.
due
Is a scheduled rule due at now (epoch ms)?
next_run
When a rule’s schedule runs next (None: no schedule, or a cron that never fires).
run
Run a rule’s then-actions for an event, in order; a failing one does not stop the rest. Does not check whether the rule matches (see check) or may run.