Repository navigation
reflex-workflow@0.1.0
First release. reflex-workflow runs durable workflows on Postgres: each workflow is a SQLAlchemy table, each row is a run, and workers in your app claim due rows and run their steps. Requires Python 3.11 or newer and SQLAlchemy 2.0.20 or newer. The documentation covers defining workflows, running workers, and how the engine works.
Features
- Define a workflow by mixing
Workflowinto a SQLAlchemy model and marking methods with@step. A step returns what runs next: another step,wake_in(step, delay),wait_for(step, ...),every(step, schedule),fan_out(children, then=step), orNoneto stop.@step(retries=N, backoff=...)retries a failing step with doubling backoff. - Start and control runs with
await Model(...).start(step),Model.by(...).run(step),.deliver(event), and.cancel(). Starting a row that hits a unique constraint starts nothing, so a key never starts two runs. - Wait for outside events: a step returns
wait_for(step, timeout=..., on_timeout=...)anddeliver(step(args), key=...)hands the event to every matching run that is waiting for it. Akeymakes delivery idempotent, andrestart=Truelets a finished run take the event by starting again. - Run a step on a schedule with
every(step, interval)orevery(step, Cron("0 9 * * MON-FRI", "America/Los_Angeles")). - Fan out with
fan_out(children, then=step): the children run as ordinary runs with their own retries, the parent continues when the last one finishes, andself.children(Child)reads them back. - Cap concurrency and rate per group with
__workflow_limit__ = Limit(by="customer", at_most=3, rate=60, per=timedelta(minutes=1)), counted across every worker. Rates use a table the application maps withRateBucket. - Pin steps to dedicated workers with
@step(lane="media")andrun_workflows(..., lanes=["media"]). - Record what each step attempt did by mapping
AttemptLog, then read it withawait run.history(). - Set up a process that starts runs and delivers events without running steps with
connect_workflows(Session). - Workers pick up new runs and events at once through Postgres
LISTEN/NOTIFY, with polling as the fallback.run_workflows(on_idle=...)andreflex_workflow.wake(timeout)let a platform wake a deployment that suspends when idle, andrun_workflows(suspends_when_idle=True)keeps an idle worker from holding a database such as Neon awake. - Models on a
MappedAsDataclassbase importWorkflow,AttemptLog, andRateBucketfromreflex_workflow.dataclassinstead. - Trace every step attempt with OpenTelemetry when
reflex-otelis instrumented. Step arguments and row columns are never recorded.