Actions are normally executed synchronously. This means that they are completed before the user is taken to the next page
- User fills in form, and clicks 'Submit'
- Record Update Event is triggered
- Actions are executed (synchronously)
- User is taken to the post-submission page
However, where the actions may take too long to complete (ie long enough to provide the user with a poor experience), it is desirable to return the user to their post-submission page immediately, and execute the actions in the background, asynchronously:
- User fills in form, and clicks 'Submit'
- Record Update Event is triggered
- User is taken to the post-submission page
- Actions are executed (asynchronously)
To set an action to be executed in the background:
- In the event tree select, New > Execution > Background
This adds a 'Background' object to the event tree. - Add the Action to be executed asynchronously as a child of the Background object.
Notes:
You can add multiple actions as children of the Background object
You can have a combination of synchronous and asynchronous actions in the same event tree
In the example above, "Update Field A" and "Update Field D" are executed synchronously, and then the post-submission page is returned to the user. 'Update Field B', 'Update Field C' and 'Send Email' are executed in the background.
By definition the system does not provide any guarantee of when the background tasks will be executed. They are placed in a queue for execution 'as soon as possible'. Where the flow that a user is taken through requires that the background actions have been executed, it is best to set a flag field when the actions are completed, and place the user in a refresh loop testing for the flag status every few seconds. (For example, you often see this in airline booking systems)
Comparison with the Delay object
The 'Background' object is functionally equivalent to a 'Delay' object with the delay is set to execute 'Now'. Both return immediately, and then execute child actions as soon as possible thereafter.
|