Skip to main content

Asynchrony / workflows

Async tasks are a useful tool for many business processes. To name a few:

  • Time-consuming, computationally-intensive calculations.
  • Executing a process at some point in the future.
  • Calling a system outside of Reboot without losing the safety guarantees Reboot provides.

All of these situations are ideal use cases for Reboot’s async task feature.

Schedule an async task

Reboot writer, transaction, and workflow methods can be executed as async tasks by scheduling them. They can be scheduled by external clients, writer, transaction, or workflow methods.

Here's an example of scheduling within a writer:

task = await self.lookup().schedule().WelcomeEmailTask(context)

In the case of a writer, the listed tasks are scheduled atomically with all of the other writer's effects, namely updating its state. If the writer's execution fails at any point, its tasks will not be scheduled, which means they will not run.

To schedule an async task for sometime in the future, you can specify when, e.g., schedule(when=...).

Task execution

Once scheduled, an async task will be run at its scheduled time. If no time is specified, it will be run after its has been persisted.

If it encounters errors, it will be retried until it eventually runs to completion.

If a task is failing because there is a bug in its implementation, it can be “hotfixed” and subsequent retries will run using the updated implementation.