s365b.jobs.liveness¶
Whether a job run is really still running.
A run reports progress every few seconds (see s365b.jobs.progress).
A run that has gone quiet belongs to a worker that stopped (restart,
crash, out of memory): it will never finish, so it is marked interrupted
rather than shown as running forever. Work it committed is kept, and the
next run continues from its last checkpoint.
Attributes¶
Functions¶
|
Keep a run marked live while work without progress reports runs. |
|
When the run last reported progress (or started, if it never did). |
|
Whether a running run has reported progress recently. |
|
Return a live run of a job, if there is one. |
|
Mark runs whose worker is gone as failed. |
Module Contents¶
- s365b.jobs.liveness.INTERRUPTED = 'Interrupted: the worker stopped during this run (restart or crash). What was stored is kept;...[source]¶
- s365b.jobs.liveness.INTERRUPTED_RESTORE = 'Interrupted: the worker stopped during this restore (restart or crash). What was restored...[source]¶
- async s365b.jobs.liveness.heartbeat(db: s365b.db.session.Database, run_id: int, every: datetime.timedelta = HEARTBEAT_EVERY) collections.abc.AsyncIterator[None][source]¶
Keep a run marked live while work without progress reports runs.
For runs that have no progress to show (retention): only the
updated_atof their progress is refreshed.- Parameters:
db – Database.
run_id – The running run.
every – How often.
- s365b.jobs.liveness.last_heartbeat(run: s365b.db.models.JobRun) datetime.datetime | None[source]¶
When the run last reported progress (or started, if it never did).
- Parameters:
run – The run.
- Returns:
The time, or
Noneif it has not started.
- s365b.jobs.liveness.is_live(run: s365b.db.models.JobRun, now: datetime.datetime | None = None) bool[source]¶
Whether a running run has reported progress recently.
- Parameters:
run – The run.
now – Current time.
- Returns:
True if it is running and was heard from within
LIVE_WITHIN.
- async s365b.jobs.liveness.live_run(s: sqlalchemy.ext.asyncio.AsyncSession, job_id: int, *, other_than: int | None = None) s365b.db.models.JobRun | None[source]¶
Return a live run of a job, if there is one.
- Parameters:
s – Database session.
job_id – The job.
other_than – A run to ignore (the caller’s own).
- Returns:
The live run, or
None.
- async s365b.jobs.liveness.reap_stale_runs(db: s365b.db.session.Database, now: datetime.datetime | None = None) list[int][source]¶
Mark runs whose worker is gone as failed.
- Parameters:
db – Database.
now – Current time.
- Returns:
IDs of the runs marked.