Scheduled Workflows
You can schedule DBOS workflows to run exactly once per time interval.
To do this, annotate the workflow with the @DBOS.scheduled
decorator and specify the schedule in crontab syntax. For example:
@DBOS.scheduled('* * * * *') # crontab syntax to run once every minute
@DBOS.workflow()
def example_scheduled_workflow(scheduled_time: datetime, actual_time: datetime):
DBOS.logger.info("I am a workflow scheduled to run once a minute. ")
Scheduled workflows must take in exactly two arguments: the time that the run was scheduled (as a datetime
) and the time the run was actually started (as a datetime
).
To learn more about crontab syntax, see this guide or this crontab editor. DBOS uses croniter to parse cron schedules, which is able to do second repetition and by default we use seconds as the first field. The specification for the DBOS variant can be found in the decorator reference.
How Scheduling Works
Under the hood, DBOS constructs an idempotency key for each workflow invocation. The key is a concatenation of the function name and the scheduled time, ensuring each scheduled invocation occurs exactly once while your application is active.