Postponing the processing of events by using when has occurred
The clause when <event> has occurred, after a delay of <calendar|absolute duration> instructs the agent to postpone the processing of the event.
You use postponed processing if an event depends on other events, if the order in which the events are processed is important, or if an action must happen after a certain duration. You can also test the presence or absence of events.
In a rule that uses the clause when <event> has occurred, after a delay of <calendar|absolute duration>, the event that occurred is the reference event. The rule is not triggered upon the arrival of this event, but it is postponed by a calendar or absolute duration. Each rule instance is applicable only once, when the condition that is expressed by the duration is satisfied.
- The rule processes a single event in the when clause.
- The rule imposes a temporal condition with an implicit reference to now that is expressed by a duration and after a delay of, for example, after a delay of 1 day or after a delay of 2 hours 30 minutes. The time now represents the most recent time stamp of all the events received so far.
- To express a delay with a fixed calendar duration, the rule can use the shorter expression when <event> has occurred <calendar duration> ago in place of after a delay of.
- The duration can be a fixed value or the value of an attribute of an event or an entity, for example, after a delay of the trial period of the customer. If the duration is expressed as an attribute, this expression must not refer to now.
- The rule can contain a condition that tests the attributes or relationship of the event, and the attributes or relationships of the bound entity.
In the following example, the normal delivery time is an attribute of the pizza order, and is defined as a duration in the business model definitions. The rule checks if the pizza order is not delivered after a delay that corresponds to the normal delivery time of the pizza order. If the order is not delivered, the order is late.
when a pizza order has occurred,
after a delay of the normal delivery time of this pizza order,
if
the order status of 'the order' is not DELIVERED
then
make it true that 'the order' is late;
when a purchase event has occurred 1 hour 15 minutes ago,
if the loyalty card amount of 'the customer' is more than 200
then ...