Automatic Trigger pattern

The svc_expr service can act as a client service on notifications, providing a simple pattern for one-shot or periodically triggered events.

In the example in Table 1, the notify operation is triggered 4 times with an interval of 5 seconds between each invocation.

Table 1. Automatic Trigger - Automatic fire
Example Description
<notify name="myNotify"  
  <prop name=""    
The myNotify operation specifies Expr as a client service.

The property specifies that the notify operation is triggered once on service startup, and then 3 more times for a total count of 4, with a 5 second interval between each trigger.

myNotify has no expr.src content, which means a notify event is fired every time myNotify is triggered.

If the property or either of its attributes were missing, default values would apply:
count ="-1"
The notify is triggered an unlimited number of times.
interval = "30s"
The time between two triggers is 30 seconds.

By default, a notify operation that has Expr as a client is triggered every 30 seconds.

In the example in Table 2, the state variable Value is checked once every hour while the Expr service is up. If Value is greater than 100, then a notify is fired outputting a field mapped to the Value variable.

Table 2. Automatic Trigger - Conditional fire
Example Description
<mix name="Mix">
  <service name="Expr"  
    <prop name="expr.state"    

  <notify name="myNotify"  
    fields="BIG value_field">  
    <prop name=""    
    <prop name="expr.src"
  case Value > 100 of
    true ->
      put("value_field", Value),

    _Otherwise ->
The Expr service specifies that Value is a state variable.

This variable has no initial value.

The myNotify operation is triggered once per hour as long as the Expr service is up.

The put/2 function is used to populate the field value_field with the value of the Value variable.

The expr.src expressions list consists of a single expression. This evaluates to true if the Value variable is greater than 100.

This means that myNotify, which gets triggered every hour, only gets fired if Value exceeds 100 when the operation is triggered.
Note: Do not manually type the <![CDATA...]]> delimiters. The Editor automatically renders text content as XML CDATA sections.