...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
/* An example of a rule that increments a counter value in the datastore */ rule incrementDS { select when test incrementDS pre { currentCounter = datastore:getItem(meta:rid, "counter")o.picolabs.wrangler.profile that selects on the initialization of the datastore newValue = currentCounter.isnull() => 0 | currentCounter + 1 } always { raise wrangler event "ds_update" attributes { "domain":meta:rid, // The domain of the key-value pairings you want to manipulate "key":"counter", // The key of the value you want to change "value":newValue // The new value for the store } } } /* This rule reacts to wrangler:ds_updated to ensure that the counter we are incrementing above is always even by checking if the new value in the store is divisible by 2 */ rule makeCounterEven { select when wrangler ds_updated pre { domain = event:attr("domain") key = event:attr("key") value = event:attr("value") } if domain == meta:rid && key == "counter" && value % 2 == 1 then noop() fired { raise wrangler event "ds_update" attributes event:attrs.put("value", value + 1) } } |
...