Skip to content

tdfs4ds.serve.activity

tdfs4ds.serve.activity

What the admin app is doing in the background, for the status bar (0.3.3.15).

A process-wide, thread-safe registry of jobs: each has a key, a label, an optional done / total count and a one-line detail. Nothing here touches the database. GET /ui/status reads snapshot().

Two ways in:

  • start(key, label) returns a handle that an existing worker updates (update) and closes (finish) -- used around the streamed panel jobs (maintenance, documentation, migration, evaluation, benchmark).
  • run_in_background(key, label, fn) runs fn(handle) in a daemon thread. A job whose key is already running is not started twice: one re-run is queued and starts when the running one ends (two builds of one store's index at once would race on the same collections).

Finished jobs stay visible for KEEP_FINISHED_S seconds so the bar can say "done" or show the error, whole.

logger module-attribute

logger = getLogger(__name__)

KEEP_FINISHED_S module-attribute

KEEP_FINISHED_S = 60.0

_LOCK module-attribute

_LOCK = Lock()

_JOBS module-attribute

_JOBS: dict = {}

_RUNNING module-attribute

_RUNNING: dict = {}

_QUEUED module-attribute

_QUEUED: dict = {}

_IDS module-attribute

_IDS = count(1)

Handle

A job's handle: update while it runs, finish once.

id instance-attribute

id = job_id

__init__

__init__(job_id: int)

update

update(done=None, total=None, detail=None) -> None

finish

finish(error: Optional[str] = None, detail: Optional[str] = None) -> None

__enter__

__enter__()

__exit__

__exit__(exc_type, exc, tb)

_describe

_describe(exc) -> str

start

start(key: str, label: str) -> Handle

Register a running job and return its handle.

is_running

is_running(key: str) -> bool

run_in_background

run_in_background(key: str, label: str, fn: Callable[[Handle], object]) -> str

Run fn(handle) in a daemon thread under key.

Returns 'started', or 'queued' when a job with the same key is running (one re-run then follows it; queueing again replaces the waiting one, which is the same work).

_launch

_launch(key, label, fn)

snapshot

snapshot(now: Optional[float] = None) -> list

Running jobs (oldest first) then jobs finished in the last KEEP_FINISHED_S seconds (newest first). Older finished jobs are dropped.

_reset

_reset() -> None

Forget every job (tests).