Synchronous and Asynchronous Automations

Differences between Synchronous and Asynchronous Automations

As their names imply, synchronous and asynchronous automations are triggers that either run in sync or out of sync with the user's actions. What this means is that:

  1. Synchronous automations will be triggered immediately when a user performs an action, and will run to completion as a single, unstopped sequence of actions.
  2. Asynchronous automations won't necessarily run immediately (though they usually do). More importantly, the automation may run in blocks. This means it's possible the user may see and interact with partial results of automations as they use Jestor (for example, importing 1,000 rows from a spreadsheet may import them in blocks of 100s).

The usages for synchronous and asynchronous automations vary, but they're usually tied to whether the automation is likely or not to cause timeouts.

How to run Synchronous Automomations

Synchronous automations are the standard way of running triggers in Jestor, and they will do so unless specified otherwise.

The example code below will run as synchronous:

if($objectNew['status'] == 'Won'){
     Jestor.create('onboarding',['name' => $objectNew['name']);

How to run Asynchronous Automomations

To run asynchronous automations, all that is necessary is to write //async as the first line of code in the trigger.

The example code below will run as asynchronous:


if($objectNew['status'] == 'Won'){
     Jestor.create('onboarding',['name' => $objectNew['name']);

As that is a very short automation, it'll likely produce the same end-result as the equivalent synchronous automation (as far as the user is concerned), but it'll run in parallel to the user experience.

Do note that, as there's no immediate feedback whether the automation worked or not, it's important that long asynchronous automations have some kind of feedback to the user when they finish running.

For example, the code below will wait ten minutes, then update a checkbox field to indicate the automation is finished.



Jestor.update('test_automation',['id_test_automation' => $objectNew['id_test_automation'], 'done' => 1]);

As a final tip, it's important to run asynchronous automations with smaller tests after you build them, as there's no way to pause them. You don't want to wait 15 minutes for an automation to finish when you've immediately realized there's something wrong with it!


Regarding Jestor.error()

As asynchronous automations run in parallel to the user's experience, Jestor.error() will work differently from synchronous automations.

The method will still work (the automation will stop and changes will be reverted), but the error message will not appear to the user. Keep that in mind when developing your triggers!