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: object

A 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; None for 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_failed or all_succeeded.

Type:

str

max_active

At most this many of its instances running at once, across all runs; None for 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_ms as null when unset; run_if only when not the default.

Return type:

dict[str, Any]

class schedr._model.tasks.ShellCommand(template)

Bases: object

A string run by a shell; it takes no references (decision 99): values go in env.

Parameters:

template (Template)

template

The command.

Type:

schedr._model.values.Template

templates()

The command line’s templates.

Returns:

A one-element list.

Return type:

list[Template]

to_json()

The command line as DAG JSON.

Returns:

{"shell": [...]}.

Return type:

dict[str, Any]

class schedr._model.tasks.ArgvCommand(args)

Bases: object

A 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: object

A @task function, 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 @branch task: 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": true for a @branch task.

Return type:

dict[str, Any]

class schedr._model.tasks.SensorMode(*values)

Bases: StrEnum

How 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: object

A wait step, @sensor or @sensor.poke: found by task ID, as a PythonKind.

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.

Type:

schedr._model.tasks.SensorMode

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:

schedr._model.tasks.SensorWaitFor | None

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": ...}, with every_ms and max_wait_ms where 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: object

What an @sensor(wait_for=...) or @trigger(wait_for=...) is called for.

A run of another DAG (RunOf, decision 353), or, with event_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; None for 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: object

A command’s part in a resource, for schedr task-ctx resource set|get.

Parameters:

cleanup_of (str | None)

cleanup_of

None for a CommandResource’s setup; for a cleanup_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: object

An inline command, run by the agent.

Parameters:
command

The command line.

Type:

schedr._model.tasks.CommandLine

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"} gives DB_URL, …).

Type:

collections.abc.Mapping[str, str]

resource

Its part in a resource, if it has one.

Type:

schedr._model.tasks.ResourceRole | None

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": ...}, with env, connection_env and resource when set.

Return type:

dict[str, Any]

class schedr._model.tasks.WaitForKind(dag, task=None, lag_ms=None, max_wait_ms=None)

Bases: object

wait_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

references()

It has no references.

Returns:

An empty list.

Return type:

list[Reference]

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: object

TriggerDagOperator: starts a run of another DAG, carried out by the master.

Decisions 357-362 and 365: the run is chained to this one; its ID is the value.

Parameters:
  • dag (str)

  • params (Mapping[str, Value])

  • planned_for (Value | None)

  • wait (bool)

  • max_wait_ms (int | None)

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: object

wait_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.key or 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: object

first_of and at_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"}, with at_least if it has a count.

Return type:

dict[str, Any]

class schedr._model.tasks.EmptyKind

Bases: object

An EmptyOperator: completed by the master, no process.

references()

An empty task has no references.

Returns:

An empty list.

Return type:

list[Reference]

to_json()

The kind as DAG JSON.

Returns:

{"kind": "empty"}.

Return type:

dict[str, Any]

class schedr._model.tasks.DeclaredTemplate(json)

Bases: object

An argument or variable as a schedr.toml declares 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

references()

None a DAG checks.

Returns:

An empty list.

Return type:

list[Reference]

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: object

A script declared in a schedr.toml (decision 293), run by the agent.

Parameters:
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:

schedr._model.tasks.ResourceRole | None

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": ..., ...}, with args and env when 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).

Type:

schedr._model.values.Value

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: object

A script as a task’s cleanup ([jobs.<name>.cleanup]).

Parameters:
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": ...}, with args when 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: object

A task’s cleanup: finally for 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’s cleanup= function.

Type:

schedr._model.tasks.CommandLine | None

timeout_ms

How long one try may run; None: the worker’s cleanup_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: None any, empty none (a function without a handles parameter 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:

schedr._model.tasks.CleanupScript | None

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": ...}), retries and retry_delay_ms, with timeout_ms and handles when 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: object

A task of a DAG.

Parameters:
id

The task’s ID, unique within its DAG.

Type:

str

kind

Its kind and what it runs.

Type:

schedr._model.tasks.TaskKind

output_type

The type of its output.

Type:

schedr._model.types.TypeDesc

settings

Its resolved settings.

Type:

schedr._model.tasks.TaskSettings

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:

schedr._model.tasks.TaskCleanup | None

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 just SUCCESS on exit 0 and "group" when it is in one.

Return type:

dict[str, Any]