schedr.dag¶
Dag, the context manager that defines a DAG, and StepDefaults.
Tasks created inside with Dag(...) belong to it. When the block ends, the DAG is checked
(no cycles) and recorded for the runner (see archive/PROJECT.md, Native API).
- class schedr.dag.StepDefaults(retries=None, retry_delay=None, timeout=None, max_wait=None, queue=None, max_output_size=None, preload=None, fresh_process=None, run_if=None, max_active=None, max_active_per_run=None, cleanup_timeout=None, cleanup_retries=None, cleanup_retry_delay=None, cleanup_anywhere=None)¶
Bases:
objectDefaults for the steps of a DAG or group, its tasks and wait steps; a step’s own win.
- Parameters:
retries (int | None)
retry_delay (timedelta | None)
timeout (timedelta | None)
max_wait (timedelta | None)
queue (str | None)
max_output_size (int | None)
preload (bool | None)
fresh_process (bool | None)
run_if (RunIf | None)
max_active (int | None)
max_active_per_run (int | None)
cleanup_timeout (timedelta | None)
cleanup_retries (int | None)
cleanup_retry_delay (timedelta | None)
cleanup_anywhere (bool | None)
- retries¶
How many times a failed attempt is retried.
- Type:
int | None
- retry_delay¶
The delay before each retry.
- Type:
datetime.timedelta | None
- timeout¶
A task’s attempt’s timeout; a wait step has
max_waitinstead.- Type:
datetime.timedelta | None
- max_wait¶
How long a wait step waits (default:
[sensors] default_max_wait); not for tasks.- Type:
datetime.timedelta | None
- queue¶
The queue steps go to.
- Type:
str | None
- max_output_size¶
The output size limit in bytes (e.g.
8 * MiB).- Type:
int | None
- preload¶
Python tasks fork from the preloaded fork server (
False: only from the bare one, for code that misbehaves next to the preloaded libraries).- Type:
bool | None
- fresh_process¶
Python tasks are always a new process, never forked (for code that misbehaves after a fork).
- Type:
bool | None
- run_if¶
When tasks run, from their upstream edges (default
RunIf.NONE_FAILED).- Type:
schedr.outcomes.RunIf | None
- max_active¶
At most this many instances of each task running at once, across all runs.
- Type:
int | None
- max_active_per_run¶
At most this many instances of each task running at once within one run (for mapped tasks).
- Type:
int | None
- cleanup_timeout¶
How long one try of a task’s cleanup may run (default: the worker’s
cleanup_timeout: 5 minutes, or less to fit in its grace period).- Type:
datetime.timedelta | None
- cleanup_retries¶
How many times a failed cleanup is retried (default 3).
- Type:
int | None
- cleanup_retry_delay¶
The delay before each cleanup retry (default 30 seconds).
- Type:
datetime.timedelta | None
- cleanup_anywhere¶
Whether the cleanup may run on another worker when this one is lost (default no: only you know whether it depends on where the task ran).
- Type:
bool | None
- options()¶
These defaults as task options.
- Returns:
The options.
- Return type:
TaskOptions
- class schedr.dag.Dag(dag_id, *, trigger=None, initial_since=None, max_active_runs=1, max_active_tasks=None, defaults=None, description=None, tags=(), params=None, notify=None)¶
Bases:
objectDefines a DAG:
with Dag("sync", trigger=Cron("0 3 * * *")): ....- Parameters:
dag_id (str) – The DAG’s ID (required, explicit).
trigger (Trigger | None) – What starts its runs:
Cron,EveryorOnce; a@triggerfunction called with its arguments (its events);RunOf(another DAG’s runs);Nonefor manual runs only.catchup,startandendare set on the trigger.initial_since (datetime | date | str | None) –
sinceof the run on the DAG’s first fire time (or of its first run without one). A date or a datetime without a time zone is read in the trigger’s time zone (UTC forEveryand no trigger).max_active_runs (int | None) – At most this many runs at a time (default 1;
None: no limit).max_active_tasks (int | None) – At most this many of its tasks running at once, across all its runs (default
None: no limit); each instance of a mapped task counts.defaults (StepDefaults | None) – Defaults for every task.
description (str | None) – Shown in the UI.
tags (Sequence[str]) – Shown in the UI and used for filtering.
params (type | None) – The run parameters it takes: a dataclass or a Pydantic model class. With a trigger, every field needs a default (scheduled runs use them). Read them with
dag_ctx.params.<field>in the DAG body (a reference) and in a task.notify (Sequence[WebhookChannel | str] | Mapping[WebhookChannel | str, Sequence[Notify]] | None) – The channels told of its runs (
schedr.notify): a list of channels, each told of the server’s default events, or a dict of channel toNotifyevents. A string names a server channel; aWebhookChannelis the DAG’s own.
- Raises:
IdError – If the DAG ID is invalid.
TypeError – For a wrong argument type, e.g. a string trigger.
ValueError – For a bad date or a non-positive
max_active_runsormax_active_tasks.