Writing a high-quality task

Here are some best practices we've found, as a community, about writing tasks that improve life for everyone.
  • Render preview actions. Do so by adding stub data to the top of your task script, allowing your task to render those actions in exactly the same way it would for a real event.
  • Watch out for action loops. If your task modifies a Shopify resource and also subscribes to that resource's update event, ensure that the task knows to not attempt to update it a second time.
  • If you generate actions that destroy data, log the original values. You never know when you'll need to go back and pull the data that was in place before your action ran.
  • If your task sometimes does nothing, log the reason why. This simple practice can save hours of customer support time later.
  • Choose purposefully between delayed subscriptions and scheduler events. Instead of using delay like "shopify/orders/create+5.days", consider a task that runs on "mechanic/scheduler/daily", querying for all orders that were created 5 days ago, processing them as a batch. This practice allows the merchant to disable/enable the task at will, without having to think about events that are already scheduled, and without having to wait x days before the task starts working again.
  • Recall that Shopify technically doesn't guarantee webhook deliverability. We've actually never seen this be a problem – sometimes they're delayed, but we haven't seen them go missing. So, write tasks that can handle being run a few hours late.
  • Include a test mode that renders a descriptive "echo" action. This action should return a summary of what the task would actually do if test mode were disabled. Use a boolean – something like {% if options.test_mode__boolean %}. Particularly for tasks that have the potential to change a lot of data at once, this allows the merchant to make an informed decision about what happens next.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.