schedr._model.tasks¶
Tasks in DAG JSON (schedr-model, task.rs): kind, what they run, resolved settings.
- schedr._model.tasks.DEFAULT_QUEUE = 'default'¶
The queue a task goes to when it names none.
- schedr._model.tasks.DEFAULT_MAX_OUTPUT_SIZE = 1048576¶
The default output size limit in bytes (1 MiB).
- schedr._model.tasks.DEFAULT_RETRY_DELAY_MS = 300000¶
The default delay between attempts in milliseconds (5 minutes).
- schedr._model.tasks.DEFAULT_OUTCOMES: tuple[tuple[str, int | None], ...] = (('SUCCESS', 0),)¶
SUCCESS, exit code 0 for a command.- Type:
A task’s outcomes when it declares none
- schedr._model.tasks.MIN_MEMORY = 16777216¶
no Python process starts in less (the worker’s own floor).
- Type:
The smallest task memory budget
- class schedr._model.tasks.TaskSettings(retries=0, retry_delay_ms=300000, timeout_ms=None, queue='default', max_output_size=1048576, preload=True, fresh_process=False, run_if='none_failed', max_active=None, max_active_per_run=None, memory_bytes=None, hard_memory_limit=False)¶
Bases:
objectA task’s settings, resolved from its own arguments and the defaults that apply.
- Parameters:
retries (int)
retry_delay_ms (int)
timeout_ms (int | None)
queue (str)
max_output_size (int)
preload (bool)
fresh_process (bool)
run_if (str)
max_active (int | None)
max_active_per_run (int | None)
memory_bytes (int | None)
hard_memory_limit (bool)
- retries¶
How many times a failed attempt is retried.
- Type:
int
- retry_delay_ms¶
The delay before each retry.
- Type:
int
- timeout_ms¶
The attempt’s timeout;
Nonefor none.- Type:
int | None
- queue¶
The queue the task goes to.
- Type:
str
- max_output_size¶
The output size limit in bytes.
- Type:
int
- preload¶
A Python task forks from the preloaded fork server (
False: only from the bare one).- Type:
bool
- fresh_process¶
A Python task is always a new process, never forked.
- Type:
bool
- run_if¶
Its trigger rule,
none_failedorall_succeeded.- Type:
str
- max_active¶
At most this many of its instances running at once, across all runs;
Nonefor no limit.- Type:
int | None
- max_active_per_run¶
The same within one run.
- Type:
int | None
- memory_bytes¶
Its own memory budget (decision 436);
None: the worker’s.- Type:
int | None
- hard_memory_limit¶
Also capped hard at
memory_bytes(RLIMIT_DATA, decision 438).- Type:
bool
- to_json()¶
The settings as DAG JSON.
- Returns:
Every setting,
timeout_msasnullwhen unset;run_ifonly when not the default.- Return type:
dict[str, Any]
- class schedr._model.tasks.ShellCommand(template)¶
Bases:
objectA string run by a shell; it takes no references (decision 99): values go in
env.- Parameters:
template (Template)
- template¶
The command.
- to_json()¶
The command line as DAG JSON.
- Returns:
{"shell": [...]}.- Return type:
dict[str, Any]
- class schedr._model.tasks.ArgvCommand(args)¶
Bases:
objectA program and its arguments, run without a shell.
- Parameters:
args (Sequence[Template])
- args¶
One template per argument; the first is the program.
- Type:
collections.abc.Sequence[schedr._model.values.Template]
- templates()¶
The command line’s templates.
- Returns:
The arguments, in order.
- Return type:
list[Template]
- to_json()¶
The command line as DAG JSON.
- Returns:
{"argv": [[...], ...]}.- Return type:
dict[str, Any]
- type schedr._model.tasks.CommandLine = ShellCommand | ArgvCommand¶
Any command line.
- class schedr._model.tasks.PythonKind(arguments=<factory>, branch=False)¶
Bases:
objectA
@taskfunction, found by task ID when the runner imports the DAG file.- Parameters:
arguments (Mapping[str, Value])
branch (bool)
- arguments¶
The arguments by parameter name.
- Type:
collections.abc.Mapping[str, schedr._model.values.Value]
- branch¶
A
@branchtask: its output is the downstream task IDs it chose.- Type:
bool
- references()¶
The arguments’ references.
- Returns:
Every reference, by parameter name order (as stored).
- Return type:
list[Reference]
- to_json()¶
The kind’s fields as DAG JSON.
- Returns:
{"kind": "python", "arguments": {...}}with names sorted, and"branch": truefor a@branchtask.- Return type:
dict[str, Any]
- class schedr._model.tasks.SensorMode(*values)¶
Bases:
StrEnumHow a wait step waits.
- LOOP = 'loop'¶
its function does the waiting.
- Type:
@sensor
- POKE = 'poke'¶
schedr calls its function every
every_ms.- Type:
@sensor.poke
- class schedr._model.tasks.SensorKind(arguments=<factory>, mode=SensorMode.LOOP, every_ms=None, max_wait_ms=None, wait_for=None, batch_ms=None)¶
Bases:
objectA wait step,
@sensoror@sensor.poke: found by task ID, as aPythonKind.- Parameters:
arguments (Mapping[str, Value])
mode (SensorMode)
every_ms (int | None)
max_wait_ms (int | None)
wait_for (SensorWaitFor | None)
batch_ms (int | None)
- arguments¶
The arguments by parameter name.
- Type:
collections.abc.Mapping[str, schedr._model.values.Value]
- mode¶
How it waits.
- every_ms¶
How often to call it (
POKE).- Type:
int | None
- max_wait_ms¶
How long it waits;
None: the worker’s[sensors] default_max_wait.- Type:
int | None
- wait_for¶
@sensor(wait_for=RunOf(...)): the run it is called for (decision 353).- Type:
- batch_ms¶
@trigger.poke(batch=...): what its pokes return is gathered this long from the first item, then sent as one event (decision 352).- Type:
int | None
- references()¶
The arguments’ references.
- Returns:
Every reference, by parameter name order (as stored).
- Return type:
list[Reference]
- to_json()¶
The kind’s fields as DAG JSON.
- Returns:
{"kind": "sensor", "arguments": {...}, "mode": ...}, withevery_msandmax_wait_mswhere they are set.- Return type:
dict[str, Any]
- class schedr._model.tasks.SensorWaitFor(dag, task, lag_ms, param, timeout_ms=None, event_name=None, event_key=None)¶
Bases:
objectWhat an
@sensor(wait_for=...)or@trigger(wait_for=...)is called for.A run of another DAG (
RunOf, decision 353), or, withevent_name, an event posted (EventNamed, decision 354).- Parameters:
dag (str | None)
task (str | None)
lag_ms (int | None)
param (str)
timeout_ms (int | None)
event_name (str | None)
event_key (Value | None)
- dag¶
The other DAG;
Nonefor an event.- Type:
str | None
- task¶
Its task;
None: the whole run.- Type:
str | None
- lag_ms¶
The run planned this long before the waiting run’s;
None: the next to end.- Type:
int | None
- param¶
The function’s parameter given the run or the event (its first).
- Type:
str
- timeout_ms¶
wait_for=..., timeout=...: how long one call may take.- Type:
int | None
- event_name¶
The event’s name, for an
EventNamed.- Type:
str | None
- event_key¶
Its key;
None: any.- Type:
schedr._model.values.Value | None
- references()¶
Its event key’s references.
- Returns:
Those of the key, if it has one.
- Return type:
list[Reference]
- to_json()¶
As DAG JSON.
- Returns:
{"run_of": {"dag": ...}, "param": ...}or{"event": {"name": ...}, "param": ...}, with what is set.- Return type:
dict[str, Any]
- class schedr._model.tasks.ResourceRole(cleanup_of=None)¶
Bases:
objectA command’s part in a resource, for
schedr task-ctx resource set|get.- Parameters:
cleanup_of (str | None)
- cleanup_of¶
Nonefor aCommandResource’s setup; for acleanup_command, the resource’s setup task.- Type:
str | None
- to_json()¶
The role as DAG JSON.
- Returns:
{"role": "setup"}or{"role": "cleanup", "setup": ...}.- Return type:
dict[str, str]
- class schedr._model.tasks.CommandKind(command, env=<factory>, connection_env=<factory>, resource=None)¶
Bases:
objectAn inline command, run by the agent.
- Parameters:
command (CommandLine)
env (Mapping[str, Template])
connection_env (Mapping[str, str])
resource (ResourceRole | None)
- command¶
The command line.
- env¶
Extra environment variables for the process.
- Type:
collections.abc.Mapping[str, schedr._model.values.Template]
- connection_env¶
Connections given as variables and files, by prefix: the connection’s name (
{"DB": "warehouse"}givesDB_URL, …).- Type:
collections.abc.Mapping[str, str]
- resource¶
Its part in a resource, if it has one.
- Type:
- references()¶
The command line’s and the environment’s references.
- Returns:
Command line references first, then environment ones by variable name.
- Return type:
list[Reference]
- to_json()¶
The kind’s fields as DAG JSON.
- Returns:
{"kind": "command", "command": ...}, withenv,connection_envandresourcewhen set.- Return type:
dict[str, Any]
- class schedr._model.tasks.WaitForKind(dag, task=None, lag_ms=None, max_wait_ms=None)¶
Bases:
objectwait_for(RunOf(...)): waits for a run of another DAG, ended by the master (decision 353).- Parameters:
dag (str)
task (str | None)
lag_ms (int | None)
max_wait_ms (int | None)
- dag¶
The DAG.
- Type:
str
- task¶
Its task;
None: the whole run.- Type:
str | None
- lag_ms¶
The run planned this long before the waiting run’s;
None: the next to end.- Type:
int | None
- max_wait_ms¶
How long it waits;
None: the master’s[sensors] default_max_wait.- Type:
int | None
- to_json()¶
The kind as DAG JSON.
- Returns:
{"kind": "wait_for", "run_of": {"dag": ...}}, with what is set.- Return type:
dict[str, Any]
- class schedr._model.tasks.TriggerDagKind(dag, params=<factory>, planned_for=None, wait=True, max_wait_ms=None)¶
Bases:
objectTriggerDagOperator: starts a run of another DAG, carried out by the master.Decisions 357-362 and 365: the run is
chainedto this one; its ID is the value.- Parameters:
- dag¶
The DAG to start a run of.
- Type:
str
- params¶
Its parameters, literals or references, checked against its schema when it runs.
- Type:
collections.abc.Mapping[str, schedr._model.values.Value]
- planned_for¶
The run’s
planned_for(a datetime or a reference);None: this run’s.- Type:
schedr._model.values.Value | None
- wait¶
Whether it waits for the run to end.
- Type:
bool
- max_wait_ms¶
How long it waits;
None: the master’s[sensors] default_max_wait.- Type:
int | None
- references()¶
The references of its parameters and its
planned_for.- Returns:
Each of them, in order.
- Return type:
list[Reference]
- to_json()¶
The kind as DAG JSON.
- Returns:
{"kind": "trigger_dag", "dag": ...}, with what is set.- Return type:
dict[str, Any]
- class schedr._model.tasks.WaitForEventKind(name, key=None, max_wait_ms=None)¶
Bases:
objectwait_for(EventNamed(...)): waits for an event posted, ended by the master.Decision 354: the event is posted through the API.
- Parameters:
name (str)
key (Value | None)
max_wait_ms (int | None)
- name¶
The event’s name.
- Type:
str
- key¶
The key it matches (a literal string, the run’s params,
dag_ctx.run.id,dag_ctx.dag_id,dag_ctx.event.keyor an upstream output);None: any.- Type:
schedr._model.values.Value | None
- max_wait_ms¶
How long it waits;
None: the master’s[sensors] default_max_wait.- Type:
int | None
- references()¶
Its key’s references.
- Returns:
Those of the key, if it has one.
- Return type:
list[Reference]
- to_json()¶
The kind as DAG JSON.
- Returns:
{"kind": "wait_for_event", "event": {"name": ...}}, with what is set.- Return type:
dict[str, Any]
- class schedr._model.tasks.FirstOfKind(at_least=None)¶
Bases:
objectfirst_ofandat_least: ended by the master, no process (decision 347).- Parameters:
at_least (int | None)
- references()¶
It has no references: its edges say what it chooses from.
- Returns:
An empty list.
- Return type:
list[Reference]
- to_json()¶
The kind as DAG JSON.
- Returns:
{"kind": "first_of"}, withat_leastif it has a count.- Return type:
dict[str, Any]
- class schedr._model.tasks.EmptyKind¶
Bases:
objectAn
EmptyOperator: completed by the master, no process.- to_json()¶
The kind as DAG JSON.
- Returns:
{"kind": "empty"}.- Return type:
dict[str, Any]
- class schedr._model.tasks.DeclaredTemplate(json)¶
Bases:
objectAn argument or variable as a
schedr.tomldeclares it, in DAG JSON already.The agent read and checked it (decision 293); it is passed on as it came, and references nothing a DAG checks (no task’s output).
- Parameters:
json (Any)
- json¶
Its DAG JSON (a template’s parts).
- Type:
Any
- to_json()¶
Its DAG JSON, as it came.
- Returns:
The JSON.
- Return type:
Any
- class schedr._model.tasks.ScriptKind(job, script, interpreter, args=(), env=<factory>, working_dir='', resource=None)¶
Bases:
objectA script declared in a
schedr.toml(decision 293), run by the agent.- Parameters:
job (str)
script (str)
interpreter (str)
args (Sequence[Template | DeclaredTemplate])
env (Mapping[str, Template | DeclaredTemplate])
working_dir (str)
resource (ResourceRole | None)
- job¶
Its declaration:
<root>:<path>#<name>.- Type:
str
- script¶
The script, relative to its script root.
- Type:
str
- interpreter¶
The interpreter’s name.
- Type:
str
- args¶
Its arguments, each one argument.
- Type:
collections.abc.Sequence[schedr._model.values.Template | schedr._model.tasks.DeclaredTemplate]
- env¶
Extra environment variables.
- Type:
collections.abc.Mapping[str, schedr._model.values.Template | schedr._model.tasks.DeclaredTemplate]
- working_dir¶
Where it runs, relative to its script root.
- Type:
str
- resource¶
Its part in a resource (
ScriptResource,cleanup_script).- Type:
- references()¶
The arguments’ and the environment’s references.
- Returns:
Argument references first, then environment ones by variable name.
- Return type:
list[Reference]
- to_json()¶
The kind’s fields as DAG JSON.
- Returns:
{"kind": "script", "job": ..., ...}, withargsandenvwhen set.- Return type:
dict[str, Any]
- type schedr._model.tasks.TaskKind = PythonKind | SensorKind | CommandKind | ScriptKind | EmptyKind | FirstOfKind | WaitForKind | WaitForEventKind | TriggerDagKind¶
Any task kind.
- class schedr._model.tasks.ExpandProduct(over)¶
Bases:
object.expand(name=values, ...): one instance per element of their cartesian product.- Parameters:
over (Mapping[str, Value])
- over¶
Each mapped argument’s list (a literal, or a reference to a list), in the order written: the first varies slowest (decision 79).
- Type:
collections.abc.Mapping[str, schedr._model.values.Value]
- references()¶
The references in what it maps over.
- Returns:
They, in argument order.
- Return type:
list[Reference]
- to_json()¶
As DAG JSON.
- Returns:
{"product": [{"name": name, "value": value}, ...]}, in the order written.- Return type:
dict[str, Any]
- class schedr._model.tasks.ExpandKwargs(over)¶
Bases:
object.expand_kwargs(values): one instance per dict of the list, its arguments.- Parameters:
over (Value)
- over¶
The list of dicts (a literal, or a reference to one).
- references()¶
The references in what it maps over.
- Returns:
They, in order.
- Return type:
list[Reference]
- to_json()¶
As DAG JSON.
- Returns:
{"kwargs": value}.- Return type:
dict[str, Any]
- type schedr._model.tasks.Expand = ExpandProduct | ExpandKwargs¶
What a mapped task’s instances vary over (decision 69).
- schedr._model.tasks.DEFAULT_CLEANUP_RETRIES = 3¶
cleanup_retries’ default.- Type:
How many times a failed cleanup is retried
- schedr._model.tasks.DEFAULT_CLEANUP_RETRY_DELAY_MS = 30000¶
cleanup_retry_delay’s default.- Type:
The delay before each cleanup retry
- class schedr._model.tasks.CleanupScript(script, interpreter, args=())¶
Bases:
objectA script as a task’s cleanup (
[jobs.<name>.cleanup]).- Parameters:
script (str)
interpreter (str)
args (Sequence[DeclaredTemplate])
- script¶
The script, relative to the task’s script root.
- Type:
str
- interpreter¶
The interpreter’s name.
- Type:
str
- args¶
Its arguments, as the declaration gives them.
- Type:
collections.abc.Sequence[schedr._model.tasks.DeclaredTemplate]
- to_json()¶
The script as DAG JSON.
- Returns:
{"script": ..., "interpreter": ...}, withargswhen set.- Return type:
dict[str, Any]
- class schedr._model.tasks.TaskCleanup(line=None, timeout_ms=None, retries=3, retry_delay_ms=30000, handles=None, anywhere=False, script=None)¶
Bases:
objectA task’s cleanup:
finallyfor each of its attempts.- Parameters:
line (CommandLine | None)
timeout_ms (int | None)
retries (int)
retry_delay_ms (int)
handles (tuple[str, ...] | None)
anywhere (bool)
script (CleanupScript | None)
- line¶
The command it runs;
None: the task’scleanup=function.- Type:
- timeout_ms¶
How long one try may run;
None: the worker’scleanup_timeout.- Type:
int | None
- retries¶
How many times it is retried after a failed try, on the same worker.
- Type:
int
- retry_delay_ms¶
The delay before each retry.
- Type:
int
- handles¶
The handle types it takes:
Noneany, empty none (a function without ahandlesparameter would never see them).- Type:
tuple[str, …] | None
- anywhere¶
Whether it may run on another worker when its own is lost.
- Type:
bool
- script¶
The script it runs, instead of a command or the function.
- Type:
- references()¶
The references of its command line.
- Returns:
They, in order; none for a function.
- Return type:
list[Reference]
- to_json()¶
The cleanup as DAG JSON.
- Returns:
Its
run("python",{"command": ...}or{"script": ...}),retriesandretry_delay_ms, withtimeout_msandhandleswhen set.- Return type:
dict[str, Any]
- class schedr._model.tasks.Task(id, kind, output_type, settings=<factory>, outcomes=(('SUCCESS', 0), ), group=None, expand=None, secrets=(), connections=(), cleanup=None)¶
Bases:
objectA task of a DAG.
- Parameters:
id (str)
kind (TaskKind)
output_type (TypeDesc)
settings (TaskSettings)
outcomes (tuple[tuple[str, int | None], ...])
group (str | None)
expand (Expand | None)
secrets (tuple[SecretDecl, ...])
connections (tuple[str, ...])
cleanup (TaskCleanup | None)
- id¶
The task’s ID, unique within its DAG.
- Type:
str
- kind¶
Its kind and what it runs.
- output_type¶
The type of its output.
- settings¶
Its resolved settings.
- outcomes¶
Its outcomes, each a name and, for a command, the exit code meaning it.
- Type:
tuple[tuple[str, int | None], …]
- group¶
The group it belongs to (the innermost), if any.
- Type:
str | None
- expand¶
What its instances vary over, for a mapped task.
- Type:
schedr._model.tasks.Expand | None
- secrets¶
The secrets it declares (
secrets=), read on demand.- Type:
tuple[schedr._model.values.SecretDecl, …]
- connections¶
The connections it opens (
connections=), by name (decision 179).- Type:
tuple[str, …]
- cleanup¶
What runs after each of its attempts (
cleanup=), if anything.- Type:
- references()¶
Every reference the task uses.
- Returns:
The kind’s references, those of what it is mapped over, then its cleanup’s.
- Return type:
list[Reference]
- to_json()¶
The task as DAG JSON (the kind’s fields are flattened into it).
- Returns:
{"id": ..., "kind": ..., ..., "settings": ..., "output_type": ...}, with"outcomes": [...]when they aren’t justSUCCESSon exit 0 and"group"when it is in one.- Return type:
dict[str, Any]