Detecting missing events

To detect the absence or presence of events, you write rules that use the when <event> has occurred clause.

To test if some events happened during a certain period, you postpone the processing of the reference event by a fixed calendar duration. In the rule, you also include a condition that checks for events that happened during the same period.

In the following rule, an action must be performed one day after a recent purchase if the amount of the purchase is more than 1000. The rule detects the absence of other purchase events during a period of one day after the recent purchase.

when a purchase event has occurred 1 day ago, called 'recent purchase'
where the amount of 'recent purchase' is more than 1000 
if
    the number of purchase events during the period of 1 day after 'recent purchase' is 0
then 
    print "No other purchase events after the recent purchase"

You can detect the absence of an event during a fixed absolute or calendar duration, or an absolute or calendar duration that is defined by an attribute of the entity that is related to the processed event.

In the following example, the rule checks if the user purchased a service before the trial period of this user expired.

when a create account event has occurred,after a delay of the trial period of 'the user',
if
    the number of purchase events is 0
then
    print "The trial period of " + the name of 'the user' + "has expired. The user must purchase the service to continue using it."

You can also detect the absence of an event in a rule that does not contain a when part, by checking that now is at the same time as another event. The conditions (definitions and if parts) must only reference events, otherwise each instance of the rule might be executed more than once.

In the following example, when a flight departure event is received by the agent, the rule checks that the agent did not receive any flight arrival event.

definitions
    set 'the flight departure' to a flight departure event;
if
    now is at the same time as the scheduled arrival time of 'the flight departure'
    and there is no flight arrival event
then
    print "Missing flight arrival event";