From 4c1ec6eebd3d24ebd6920aa4b69897e0afe1c399 Mon Sep 17 00:00:00 2001 From: chuck-dbos <134347445+chuck-dbos@users.noreply.github.com> Date: Fri, 7 Mar 2025 13:53:26 -0500 Subject: [PATCH] Clarify Python scheduled function requirements (#315) --- docs/python/reference/decorators.md | 2 +- docs/python/tutorials/scheduled-workflows.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/python/reference/decorators.md b/docs/python/reference/decorators.md index b10583f2f..226174045 100644 --- a/docs/python/reference/decorators.md +++ b/docs/python/reference/decorators.md @@ -101,7 +101,7 @@ DBOS.scheduled( Run a function on a schedule specified using [crontab](https://en.wikipedia.org/wiki/Cron) syntax. See [here](https://docs.gitlab.com/ee/topics/cron/) for a guide to cron syntax and [here](https://crontab.guru/) for a crontab editor. -The annotated function must take in two parameters: The time that the run was scheduled (as a `datetime`) and the time that the run was actually started (also a `datetime`). +The annotated function must take in two parameters: The time that the run was scheduled (as a `datetime`) and the time that the run was actually started (also a `datetime`). Functions within classes may be marked as `@staticmethod` to meet this requirement. **Example:** ```python diff --git a/docs/python/tutorials/scheduled-workflows.md b/docs/python/tutorials/scheduled-workflows.md index 687882dd5..5f7445345 100644 --- a/docs/python/tutorials/scheduled-workflows.md +++ b/docs/python/tutorials/scheduled-workflows.md @@ -14,7 +14,7 @@ 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`). +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`). Note that this means scheduled workflows should either be plain functions, or be `@staticmethod` class members. To learn more about crontab syntax, see [this guide](https://docs.gitlab.com/ee/topics/cron/) or [this crontab editor](https://crontab.guru/). DBOS uses [croniter](https://pypi.org/project/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](../reference/decorators.md#scheduled).