Workflows
DAG workflow builder, run handles, gate APIs, and supporting types.
DAG workflow builder, run handles, gate APIs, and supporting types.
DAG workflow builder, execution handles, and analysis tools.
WorkflowBuilder for a workflow DAG.
Workflow(
name: str = "workflow",
version: int = 1,
on_failure: str = "fail_fast",
cache_ttl: float | None = None,
)| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | "workflow" | Workflow name (used for definition storage) |
version | int | 1 | Version number |
on_failure | str | "fail_fast" | Error strategy: "fail_fast" or "continue" |
cache_ttl | float | None | None | Cache TTL in seconds for incremental runs |
step()wf.step(
name: str,
task: TaskWrapper,
*,
after: str | list[str] | None = None,
args: tuple = (),
kwargs: dict | None = None,
queue: str | None = None,
max_retries: int | None = None,
timeout_ms: int | None = None,
priority: int | None = None,
fan_out: str | None = None,
fan_in: str | None = None,
condition: str | Callable | None = None,
) -> WorkflowAdd a task step. Returns self for chaining.
gate()wf.gate(
name: str,
*,
after: str | list[str] | None = None,
condition: str | Callable | None = None,
timeout: float | None = None,
on_timeout: str = "reject",
message: str | Callable | None = None,
) -> WorkflowAdd an approval gate step.
visualize()wf.visualize(fmt: str = "mermaid") -> strRender the DAG as a Mermaid or DOT diagram string.
ancestors() / descendants()wf.ancestors(node: str) -> list[str]
wf.descendants(node: str) -> list[str]topological_levels()wf.topological_levels() -> list[list[str]]stats()wf.stats() -> dict[str, int | float]Returns {nodes, edges, depth, width, density}.
critical_path()wf.critical_path(costs: dict[str, float]) -> tuple[list[str], float]Returns (path, total_cost) — the longest-weighted path.
execution_plan()wf.execution_plan(max_workers: int = 1) -> list[list[str]]bottleneck_analysis()wf.bottleneck_analysis(costs: dict[str, float]) -> dict[str, Any]Returns {node, cost, percentage, critical_path, total_cost, suggestion}.
WorkflowRunHandle for a submitted workflow run.
status()run.status() -> WorkflowStatuswait()run.wait(timeout: float | None = None, poll_interval: float = 0.1) -> WorkflowStatusBlock until the workflow reaches a terminal state. Raises WorkflowTimeoutError
on timeout.
cancel()run.cancel() -> Nonenode_status()run.node_status(node_name: str) -> NodeStatusvisualize()run.visualize(fmt: str = "mermaid") -> strRender the DAG with live node status colors.
WorkflowProxyReturned by @queue.workflow(). Wraps a factory function.
submit()proxy.submit(*args, **kwargs) -> WorkflowRunBuild and submit the workflow.
build()proxy.build(*args, **kwargs) -> WorkflowMaterialize without submitting.
as_step()proxy.as_step(**params) -> SubWorkflowRefReturn a reference for use as a sub-workflow step.
Added to Queue via QueueWorkflowMixin:
submit_workflow()queue.submit_workflow(
workflow: Workflow,
*,
incremental: bool = False,
base_run: str | None = None,
) -> WorkflowRunapprove_gate()queue.approve_gate(run_id: str, node_name: str) -> Nonereject_gate()queue.reject_gate(run_id: str, node_name: str, error: str = "rejected") -> None@queue.workflow()@queue.workflow(name: str | None = None, *, version: int = 1)
def factory() -> Workflow: ...WorkflowStateclass WorkflowState(str, Enum):
PENDING = "pending"
RUNNING = "running"
COMPLETED = "completed"
FAILED = "failed"
CANCELLED = "cancelled"
PAUSED = "paused"NodeStatusclass NodeStatus(str, Enum):
PENDING = "pending"
READY = "ready"
RUNNING = "running"
COMPLETED = "completed"
FAILED = "failed"
SKIPPED = "skipped"
WAITING_APPROVAL = "waiting_approval"
CACHE_HIT = "cache_hit"WorkflowStatus@dataclass
class WorkflowStatus:
run_id: str
state: WorkflowState
started_at: int | None
completed_at: int | None
error: str | None
nodes: dict[str, NodeSnapshot]NodeSnapshot@dataclass
class NodeSnapshot:
name: str
status: NodeStatus
job_id: str | None
error: str | NoneWorkflowContext@dataclass(frozen=True)
class WorkflowContext:
run_id: str
results: dict[str, Any]
statuses: dict[str, str]
params: dict[str, Any] | None
failure_count: int
success_count: intGateConfig@dataclass
class GateConfig:
timeout: float | None = None
on_timeout: str = "reject"
message: str | Callable | None = None