Avoiding action loops
In some cases, it's possible to inadvertently create an action loop – in which a task run produces an action, which creates an event, which results in a task run that produces the same action all over again.
Manual prevention
When you compose your task scripts, be mindful of opportunities for new events to arise. These places include any use of the "event" action (which creates events in Mechanic), or any calls to Shopify (the "shopify" action) or to outside APIs (the "http" action) that could result in new inbound events.
When responding to update events from Shopify (e.g. "shopify/products/update"), make sure that your task can tell when it should take action, and when it should do nothing. For example, a tagging task should be able to take action for a resource that needs tags, and also be able to do nothing if the resource is already tagged.
Automated prevention
In some cases, Mechanic actively works to prevent action loops.
- For tasks responding to "mechanic/actions/perform" (see Responding to action results), Mechanic will detect task runs that have results identical to their predecessors. In these cases, Mechanic will mark the task run as failed.
- For tasks responding to an update event from Shopify (e.g. "shopify/products/update"), Mechanic will detect repeated, identical task runs that create "shopify" actions that appear to be prompting Shopify to create repeated update events. In these cases, Mechanic will pause all action runs generated by the flagged task run, thus breaking the loop (see Paused actions).