Tasks
In Mechanic, a task is a bundle of logic and configuration, that responds to and interprets events. The result of a task can define actions, which are the task's opportunities to have an effect on the world.
A task responds to events based on its subscriptions. When an event is received that matches a subscription, the task processes the event using its code. The code has access to the event data; it also has access to the user's task configuration, through options. Task code is written in Liquid, and is responsible for rendering a series of JSON objects (including action, error, and log objects), defining work to be performed once task rendering is complete.
A task uses its preview to communicate ahead of time the work it intends to do. Previews are important for users, and are also important for Mechanic itself – Mechanic looks to the task preview to understand what permissions a task requires.
Tasks may be written from scratch, or installed from the Mechanic library (available in-app and on GitHub). Once installed, a task's code may be modified at any time.
Working on getting better at task-writing? See Practicing writing tasks, and Writing a high-quality task.

Example

This very basic task subscribes to shopify/customers/create, and renders an Email action, using an email subject and body drawn from user-configured options.
Subscriptions
1
shopify/customers/create
Copied!
Code
1
{% action "email" %}
2
{
3
"to": {{ options.email_recipient__email_required | json }},
4
"subject": {{ options.email_subject__required | json }},
5
"body": {{ options.email_body__multiline_required | newline_to_br | json }},
6
"from_display_name": {{ shop.name | json }}
7
}
8
{% endaction %}
Copied!
Last modified 6mo ago
Copy link
Contents
Example