s365b.jobs.liveness =================== .. py:module:: s365b.jobs.liveness .. autoapi-nested-parse:: Whether a job run is really still running. A run reports progress every few seconds (see :mod:`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 ---------- .. autoapisummary:: s365b.jobs.liveness.LIVE_WITHIN s365b.jobs.liveness.STALE_AFTER s365b.jobs.liveness.INTERRUPTED s365b.jobs.liveness.INTERRUPTED_RESTORE s365b.jobs.liveness.HEARTBEAT_EVERY Functions --------- .. autoapisummary:: s365b.jobs.liveness.heartbeat s365b.jobs.liveness.last_heartbeat s365b.jobs.liveness.is_live s365b.jobs.liveness.live_run s365b.jobs.liveness.reap_stale_runs Module Contents --------------- .. py:data:: LIVE_WITHIN .. py:data:: STALE_AFTER .. py:data:: INTERRUPTED :value: 'Interrupted: the worker stopped during this run (restart or crash). What was stored is kept;... .. py:data:: INTERRUPTED_RESTORE :value: 'Interrupted: the worker stopped during this restore (restart or crash). What was restored... .. py:data:: HEARTBEAT_EVERY .. py:function:: heartbeat(db: s365b.db.session.Database, run_id: int, every: datetime.timedelta = HEARTBEAT_EVERY) -> collections.abc.AsyncIterator[None] :async: Keep a run marked live while work without progress reports runs. For runs that have no progress to show (retention): only the ``updated_at`` of their progress is refreshed. :param db: Database. :param run_id: The running run. :param every: How often. .. py:function:: last_heartbeat(run: s365b.db.models.JobRun) -> datetime.datetime | None When the run last reported progress (or started, if it never did). :param run: The run. :returns: The time, or ``None`` if it has not started. .. py:function:: is_live(run: s365b.db.models.JobRun, now: datetime.datetime | None = None) -> bool Whether a running run has reported progress recently. :param run: The run. :param now: Current time. :returns: True if it is running and was heard from within :data:`LIVE_WITHIN`. .. py:function:: live_run(s: sqlalchemy.ext.asyncio.AsyncSession, job_id: int, *, other_than: int | None = None) -> s365b.db.models.JobRun | None :async: Return a live run of a job, if there is one. :param s: Database session. :param job_id: The job. :param other_than: A run to ignore (the caller's own). :returns: The live run, or ``None``. .. py:function:: reap_stale_runs(db: s365b.db.session.Database, now: datetime.datetime | None = None) -> list[int] :async: Mark runs whose worker is gone as failed. :param db: Database. :param now: Current time. :returns: IDs of the runs marked.