Skip to main content

Introduction to Workflows

Temporal Workflows orchestrate your Activities.

They are resilient - they can run and keep running for years, even if the underlying infrastructure fails. If the application itself crashes, Temporal will automatically recreate its Workflow’s pre-failure state so it can continue right where it left off.

In our reimbursement example, if the network fails right after the withdrawal but before the deposit, Temporal recreates the Workflow Execution from its last known state and continues as if no failure ever occurred.

This Workflow orchestrates our two Activities.

from datetime import timedelta
from temporalio import workflow
from activities import withdraw_money, deposit_money

@workflow.defn
class ReimbursementWorkflow:
@workflow.run
async def run(self, user_id: str, amount: float) -> str:
await workflow.execute_activity(
withdraw_money,
amount,
start_to_close_timeout=timedelta(seconds=5) # maximum time allowed for a single attempt of an Activity to execute
)

await workflow.execute_activity(
deposit_money,
amount,
start_to_close_timeout=timedelta(seconds=5) # maximum time allowed for a single attempt of an Activity to execute
)

return f"reimbursement to {user_id} successfully complete"
4 / 9