schedr.outcomes

Outcomes: which kind of success a task had, and what routes on it (.on(...)).

Every task has an outcome enum (see archive/PROJECT.md, Task results and outcomes):

  • DefaultOutcome (SUCCESS) for an ordinary return type, an empty task and a command without outcomes=;

  • a declared Outcome enum: def check() -> Check (the member is the outcome, the output None), or CommandOperator(..., outcomes=Check) (the members’ values are exit codes);

  • an implicit one from an outcome union: a return type that is a union of two or more dataclasses, Pydantic models and None (-> Rows | Unavailable), one outcome per class, named after it ("None" for None).

In the backend an outcome is a name; the classes and enums exist only here.

class schedr.outcomes.Data

Bases: object

The base of outcome classes: a subclass is a dataclass, and type checkers see .on.

class Rows(Data, frozen=True): rows: list[Row] is what @dataclass(frozen=True) would make, with nothing else at run time. Type checkers read a call of a task returning Rows | Unavailable as that union, so .on(Rows) (typed Rows) and >> must come from the class: Data declares them for type checkers only. Dataclass options are class keywords (frozen, eq, order, kw_only, unsafe_hash, repr); slots isn’t one (it makes a new class).

Ordinary data (not an outcome) stays a plain @dataclass.

class schedr.outcomes.DefaultOutcome(*values)

Bases: Outcome

The outcome of a task without outcomes of its own.

class schedr.outcomes.Done(*args, **kwargs)

Bases: Protocol

What a call of a task without data gives, for type checkers: something to order.

A task returning None, an edge on an Outcome member (check().on(Check.CHANGED)) and .on(None) are typed Done: >> orders them, nothing can be passed.

class schedr.outcomes.Outcome(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The base of a task’s declared outcomes: subclass it, one member per outcome.

For a command task each member’s value is the exit code meaning it (a declared code is a success, any other a failure); for a Python task returning a member the values are ignored. One enum can serve both, so a check can move between Bash and Python without changing any edge:

class Check(Outcome):
    CHANGED = 0
    UNCHANGED = 3

In a DAG body, a call of a task returning one is typed as the enum (its output is None): check().on(Check.CHANGED) >> notify, react(check().outcome).

class schedr.outcomes.RunIf(*values)

Bases: StrEnum

When a task runs, from its upstream edges (its trigger rule).

An edge not taken (an .on(...) whose outcome didn’t happen, or a skipped upstream task) counts as skipped.

NONE_FAILED = 'none_failed'

skipped when all were skipped; a reference whose edge wasn’t taken passes None.

Type:

Every edge that wasn’t skipped succeeded and at least one did (the default)

ALL_SUCCEEDED = 'all_succeeded'

skipped when one was skipped, so its data is never None.

Type:

Every edge succeeded

exception schedr.outcomes.TypingHint

Bases: UserWarning

A DAG that runs as written, but that type checkers will read wrongly.

E.g. an outcome class deriving from neither schedr.Data nor schedr.pydantic.Model: .on(Cls) works when the DAG runs, but type checkers reject it (see schedr.on). schedr dags check prints these; pytest lists them in its warnings summary.