Jobs¶
Portable progress, cancellation, and shell-job contracts.
Shell jobs are deliberately smaller than consumer domain queues. A job here is work that this TUI process started and can present, gate, or cancel. Durable processing queues, leases, retries, and run records stay with the consuming application.
BlockDecision
dataclass
¶
BlockDecision(allowed: bool, reason: str | None = None)
CancellationMode ¶
Bases: StrEnum
How the shell should present and route cancellation for an action.
CancellationRequested ¶
Bases: RuntimeError
Raised by cooperative runners when the operator has requested cancellation.
CancellationToken ¶
JobManager ¶
JobManager(policy: JobPolicy | None = None)
Multi-job-capable manager with a conservative default policy.
The manager does not execute work itself. Textual workers, threads, or synchronous test harnesses own execution and report lifecycle changes back here.
start ¶
start(
spec: JobSpec,
*,
job_id: str | None = None,
metadata: Mapping[str, object] | None = None,
) -> tuple[JobSnapshot, ThreadCancellationToken]
JobPolicy ¶
Bases: Protocol
In-process gate for shell jobs.
JobSnapshot
dataclass
¶
JobSnapshot(
job_id: str,
spec: JobSpec,
started_at: float,
progress: ProgressEvent | None = None,
cancelling: bool = False,
metadata: Mapping[str, object] = dict(),
)
Immutable view of a shell job for policy, bars, and tests.
metadata
class-attribute
instance-attribute
¶
metadata: Mapping[str, object] = field(default_factory=dict)
JobSpec
dataclass
¶
JobSpec(
key: str,
label: str,
resources: frozenset[str] = frozenset(),
effects: frozenset[str] = frozenset(),
cancellation: CancellationMode = CancellationMode.UNSUPPORTED,
foreground: bool = True,
)
What the shell needs to decide whether work may start.
cancellation
class-attribute
instance-attribute
¶
cancellation: CancellationMode = (
CancellationMode.UNSUPPORTED
)
ProgressEvent
dataclass
¶
ProgressEvent(
event: str,
phase: str | None = None,
completed: int = 0,
total: int | None = None,
unit: str | None = None,
message: str | None = None,
timestamp: datetime = (lambda: datetime.now(UTC))(),
)
One portable progress update emitted by a runner.
timestamp
class-attribute
instance-attribute
¶
timestamp: datetime = field(
default_factory=lambda: datetime.now(UTC)
)
ProgressSink ¶
Bases: Protocol
Consumer runners call this; widgets never need to know the runner type.
RecordingProgressSink ¶
RecordingProgressSink()
SingleForegroundJobPolicy ¶
Default policy: one foreground job, plus no overlapping explicit resources.