featherweight.events¶
events ¶
Following a job: its events, as an async stream, and waiting for it to end.
The database writes an event in the transaction of every status change (see Database). Here they are read:
- in the process that wrote them, the database publishes each event at commit, so a listener hears it at once, with no
polling;
- from another process, the events table must be read, so each Database object has one reader task that polls it, with
a growing delay, for every open stream together (one query, however many streams), and fans the events out.
A stream reads the stored events first and listens second, and drops what it has already given, so it misses nothing and gives
nothing twice. See docs/specs/submitted-jobs.md.
job_events
async
¶
The events of a job, after the sequence number after: the stored ones first, then each as it happens, ending after
a final one (succeeded, failed or cancelled). A stream that starts late replays what it missed, and one that
reconnects passes the seq of the last event it had. LookupError for a job that does not exist.
wait_for_job
async
¶
wait_for_job(
db: Database, job_id: str, timeout: float | None = None
) -> JobRow
The job, once it is final (SUCCESS, FAILED or CANCELLED). It reads the status, and if the job is not final it
follows the events, so there is no gap between looking and listening. TimeoutError after timeout seconds,
LookupError for a job that does not exist. A convenience for scripts and tests: a web handler should return the job id.