Subscriptions control what events a task responds to. They have two pieces:

  1. The event topic
  2. Optionally, a time delay

Event topics are plentiful. Time delays can be in minutes, hours, days, weeks, months, or years.

A warning about time delays

The variables Mechanic makes available to you (customer for a customer-related event, product for a product-related event, etc) all contain the data that arrives with the original event. If you are using a time delay, this data will be stale/outdated by the time the task runs. Using out-of-date data is problematic, to say the least!

The solution: reload the variable. For example, add this to the top of your task script to make sure you are using the most recent customer information available:

{% unless event.preview %}
  {% assign customer = customer.reload %}
{% endunless %}

This code ensures that, when performing a task against a real, non-preview event, the customer variable will contain up-to-date values. We prevent this from happening during previews, because Mechanic does not permit live access to the Shopify API during preview mode.

Standard subscriptions

By default, subscriptions are specified as a simple list, separated by newlines. This is the easiest way to establish when a task is supposed to run.

Examples

  • shopify/customers/create 
  • mechanic/scheduler/tuesday+9.hours 

Liquid subscriptions

By clicking the "Enable Liquid" link in the subscription editor, you can start editing your subscriptions using Liquid code.

Combined with the options object, this creates a powerful mechanism for subscribing tasks based on merchant configuration. This means subscriptions can be conditionally added and dynamically generated.

When composing your Liquid subscriptions, make sure that one event subscription is given per line.

Examples

shopify/orders/create

{% if options.send_email_when_order_cancelled__boolean %}
  shopify/orders/cancelled
{% endif %}
shopify/orders/paid+{{ options.days_to_wait_before_followup__number_required }}.days
shopify/customers/create{% if options.minutes_to_wait__number != blank %}+{{ options.minutes_to_wait__number }}.minutes{% endif %}

Demo

Did this answer your question?