Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Trigger only activating when message is MHeartbeat?Forum ↗

Trigger only activating when message is MHeartbeat?

App Development2 posts239 viewsLast activity Jan 2023
LU
Luis_AlmeidaOP
Jan 2023

Hello, is it possible to make it so the trigger only activates and processes the rule only if the message received was MHeartbeat?
I have a registeredTemplate that is queried in the rule and this template is constantly being created and altered in the ledger, leading to unnecessary processing on the trigger. As such, I’d like for the trigger to only query the ledger and emitCommands every minute instead.
As far as I understand, this might be possible by altering the updateState?

trigger : Trigger ()
trigger = Trigger
  { initialize = const ()
  , updateState = \_-> ()
  , rule = triggerRule
  , registeredTemplates = RegisteredTemplates
      [ registeredTemplate @Token
      ]
  , heartbeat = Some $ minutes 1
  }
BE
bernhard
Jan 2023

Change your state from () to something like data MyTriggerState = MyTriggerState with heartbeatReceived: Bool. Then in the updateState, you set that boolean to True when you receive a heartbeat, and in the rule, you only call triggerRule when heartbeatReceived == True and then set it to False again.

← Back to Discussions