operonx.app.jobs¶
Jobs run a graph over data that does not talk back — a list, a .jsonl
file, a function that yields items — one run per item, every result kept,
with a record per run. steps=[...] runs jobs in order. The guide:
Jobs.
Job¶
Job
¶
Job(
name: str,
*,
graph: Any = None,
items: Any = None,
input: Optional[str] = None,
inputs: Optional[Dict[str, Any]] = None,
key: Union[str, KeyFn, None] = None,
output: Union[str, Path, Callable[..., Any], None] = None,
reduce: Any = None,
concurrency: int = 4,
on_error: str = "skip",
retry: Optional[Retry] = None,
timeout: Optional[float] = None,
preflight: Optional[Sequence[str]] = None,
steps: Optional[Sequence["Job"]] = None,
trace: Any = None,
keep_results: bool = True,
record_dir: Union[str, Path, None] = None,
on_item: Optional[Callable[[Any], Any]] = None,
description: str = "",
fail_run: Optional[bool] = None,
schedule: Any = None,
)
See the module docstring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The job's name: the CLI argument and the record's folder. |
required |
graph
|
Any
|
A module-level |
None
|
items
|
Any
|
What to loop over: a function returning an iterable (called
on every run), an iterable or async iterable, or a |
None
|
input
|
Optional[str]
|
The graph parameter that receives the whole item. Without
it, a dict item fills parameters by name and anything else goes
to the graph's only free parameter. A graph with |
None
|
inputs
|
Optional[Dict[str, Any]]
|
Fixed graph inputs for every item ( |
None
|
key
|
Union[str, KeyFn, None]
|
The item field that identifies it, or a function of the item. Without one each item gets a random id and the job cannot resume. |
None
|
output
|
Union[str, Path, Callable[..., Any], None]
|
Also export each successful result as it finishes: a
|
None
|
reduce
|
Any
|
A module-level |
None
|
concurrency
|
int
|
Items in flight at once. |
4
|
on_error
|
str
|
|
'skip'
|
fail_run
|
Optional[bool]
|
|
None
|
retry
|
Optional[Retry]
|
|
None
|
timeout
|
Optional[float]
|
Seconds one item's run may take; past it, the run is
cancelled and the item recorded |
None
|
preflight
|
Optional[Sequence[str]]
|
Resource keys ( |
None
|
steps
|
Optional[Sequence['Job']]
|
Instead of |
None
|
trace
|
Any
|
Trace consumers for the runs ( |
None
|
keep_results
|
bool
|
Keep each result in the record's |
True
|
on_item
|
Optional[Callable[[Any], Any]]
|
Called with each item's |
None
|
record_dir
|
Union[str, Path, None]
|
Where runs are recorded ( |
None
|
description
|
str
|
One line, for |
''
|
schedule
|
Any
|
|
None
|
Source code in operonx/app/jobs/job.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
Methods:¶
engine
¶
The compiled Operon, built once.
Source code in operonx/app/jobs/job.py
reducer
¶
The compiled reduce graph, built once (None without one).
Source code in operonx/app/jobs/job.py
has_doors
¶
True when the graph reads items through an ingress door — the
serving shape (:func:operonx.app.doors.has_doors).
Source code in operonx/app/jobs/job.py
bind
¶
The run inputs for one item of a graph without doors
(:func:operonx.app.doors.bind_item).
Source code in operonx/app/jobs/job.py
item_of
¶
What the graph receives for one raw item — the item itself; an
Eval hands over a case's input.
key_of
¶
The item's identity, as a non-empty string.
Source code in operonx/app/jobs/job.py
run
async
¶
run(
*,
resume: bool = False,
record_dir: Union[str, Path, None] = None,
on_item: Optional[Callable[[Any], Any]] = None,
trigger: Optional[Mapping[str, Any]] = None,
) -> JobRun
Run the job once and return its record. record_dir overrides
where it is written (for this run, and every step's); on_item is
called with each item's ItemResult as it is recorded; trigger
says what started it (a schedule's tick), kept in the record.
Source code in operonx/app/jobs/job.py
run_sync
¶
main
¶
This job as a command line; returns the exit status. Takes the
flags operonx run has, minus the job name.
Source code in operonx/app/jobs/job.py
records
¶
describe
¶
What the job is, for run.json and --list. No secrets: only
the names of things.
Source code in operonx/app/jobs/job.py
The record¶
JobRun
dataclass
¶
JobRun(
job: str,
run_id: str,
path: Path,
status: str,
started: str,
ended: Optional[str],
counts: Dict[str, int],
items: List[ItemResult] = list(),
resume_from: Optional[str] = None,
meta: Dict[str, Any] = dict(),
)
A finished (or in-flight) run, read back from its two files.
Attributes¶
results
property
¶
{key: result} for every item that produced something — this
run's and, after --resume, the earlier runs' too. Read from
results.jsonl; empty when the job kept no results.
reduced
property
¶
What the job's reduce graph returned (None without one,
or when it did not run).
Methods:¶
load
classmethod
¶
A run from its directory. items=False reads run.json
alone: no items, and the counts as run.json wrote them.
Source code in operonx/app/jobs/record.py
ItemResult
dataclass
¶
ItemResult(
key: str,
status: str,
error: Optional[str] = None,
trace_id: Optional[str] = None,
ms: float = 0.0,
sent: int = 0,
attempts: int = 1,
verdict: Optional[Dict[str, Any]] = None,
trace: Any = None,
result: Any = None,
)
Methods:¶
as_dict
¶
The record line's fields. Shallow: the line is serialized at
once, and a deep copy of an eval's verdict (asdict) was most of
what writing an item cost (scripts/bench_eval_overhead.py).
Source code in operonx/app/jobs/record.py
RunRecord
¶
RunRecord(
root: str | Path,
job: str,
*,
meta: Optional[Dict[str, Any]] = None,
resume_from: Optional[str] = None,
keep_results: bool = True,
)
The writer. Opened when the run starts, finished exactly once.
Source code in operonx/app/jobs/record.py
Methods:¶
result
¶
Keep one item's result in results.jsonl (when the job keeps
results). Flushed at once, like the item line.
Source code in operonx/app/jobs/record.py
finish
¶
finish(
status: str,
error: Optional[str] = None,
*,
counts: Optional[Dict[str, int]] = None,
extra: Optional[Dict[str, Any]] = None,
) -> JobRun
Close the record. counts adds to the item counts; extra
lands in run.json beside the job's description (what reduce
returned, a steps job's steps, an eval's numbers).
Source code in operonx/app/jobs/record.py
Items¶
iter_items
async
¶
Every item, in order, as an async iterator.
Source code in operonx/app/jobs/items.py
The session¶
JobSession
¶
Bases: BoundedSession
One item in; what egress sends, kept as the item's result.