Skip to main content

Steps

When using DBOS workflows, we recommend annotating any function that performs complex operations or accesses external APIs or services as a step.

You can turn any Python function into a step by annotating it with the @DBOS.step decorator. Here's a simple example:

@DBOS.step()
def example_step():
return requests.get("https://example.com").text

You should make a function a step if you're using it in a DBOS workflow and it accesses an external API or service, like serving a file from AWS S3, calling an external API like Stripe, or accessing an external data store like Elasticsearch.

Making a function a step has two benefits:

  1. It lets workflows know this function performs a complex operation or interacts with an external service, so the workflow can guarantee those operations or interactions happen exactly-once.

  2. DBOS provides configurable automatic retries for steps to more easily handle transient errors.

Configurable Retries

You can optionally configure a step to automatically retry any exception a set number of times with exponential backoff. Retries are configurable through arguments to the step decorator:

DBOS.step(
retries_allowed: bool = False,
interval_seconds: float = 1.0,
max_attempts: int = 3,
backoff_rate: float = 2.0
)

For example, we can configure example_step to retry exceptions (such as if example.com is temporarily down) up to 10 times:

@DBOS.step(retries_allowed=True, max_attempts=10)
def example_step():
return requests.get("https://example.com").text