Responding to action results
Last updated
Was this helpful?
Last updated
Was this helpful?
Action runs are performed asynchronously, . This means their results aren't available to the Liquid task code that defined them.
To respond to action results, add a task subscription to the mechanic/actions/perform event topic. When a task includes this subscription, Mechanic will generate an event with that topic for every action that the task completes. This event will only ever be responded to by the task that generated it; it will never be sent to other tasks.
Common use cases:
Evaluating response codes or payloads
See
Evaluating the results of GraphQL mutations
Using content from generated
Events with the topic mechanic/actions/perform are, by nature, always . As such, their event
variable contains a reference to the event's parent. This means a task may use event.parent.data
to access all the data that informed the construction of the action in question. (Note that only the previous 5 generations of parents are available.)
A mechanic/actions/perform event also provides task runs with an action
variable (containing the same information available in event.data
). This variable contains the original (including its type, options, and meta information), and data from the run in which the action was performed.
Common sources of information for followup task runs:
action.options
â the original options defined for the action
action.run.ok
â true
or false
, indicating the action's success
action.run.result
â the value (if any) generated by the action run
action.run.error
â the error (if any) raised during the action run
action.meta
â the given in the action's definition
It's important to specifically account for the mechanic/actions/perform topic when writing a task script, minding the fact that improper composition could result in an infinite loop.
Mechanic will step in and forcibly fail subsequent task runs that contain results identical to their predecessors.
This example cycles between three different modes of operation, depending on the recorded in the action definition. And, by checking on action.run.ok
at the very beginning, the task is also able to "break" into failure-handling mode, in which an email is sent to an administrator.