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 = logging.getLogger(__name__)

KEEP_FINISHED_S module-attribute

KEEP_FINISHED_S = 60.0

_LOCK module-attribute

_LOCK = threading.Lock()

_JOBS module-attribute

_JOBS: dict = {}

_RUNNING module-attribute

_RUNNING: dict = {}

_QUEUED module-attribute

_QUEUED: dict = {}

_IDS module-attribute

_IDS = itertools.count(1)

_REQUESTS module-attribute

_REQUESTS = {'n': 0}

_CURRENT_REQUEST module-attribute

_CURRENT_REQUEST: ContextVar = contextvars.ContextVar('tdfs4ds_request_activity', default=None)

ROUTE_LABELS module-attribute

ROUTE_LABELS = {'/ui/dashboard/report': 'Overview report', '/ui/dashboard/storage': 'Storage counts', '/ui/dashboard/orphans': 'Orphan scan', '/ui/dashboard': 'Overview', '/ui/workflow': 'Health check', '/ui/efs': 'Store map', '/ui/catalog': 'Feature catalog', '/ui/lineage': 'Lineage', '/ui/doc/coverage': 'Documentation coverage', '/ui/doc': 'Documentation', '/ui/runs': 'Runs', '/ui/timemgr': 'Time managers', '/ui/framework': 'Framework cost', '/ui/params': 'Parameters', '/ui/home': 'Home', '/ui/dsbuild': 'Dataset builder', '/ui/parallel': 'Execution plan', '/ui/migration': 'Migration', '/ui/attached': 'Attached objects', '/ui/glossary': 'Glossary', '/ui/datasets': 'Datasets', '/ui/impact': 'Impact study', '/ui/qopt': 'Query optimization', '/ui/benchmark': 'Benchmark', '/ui/maintenance': 'Maintenance', '/ui/search': 'Search'}

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)

RequestState

What the middleware keeps for one request: the step text, and the activity once there is one.

step instance-attribute

step = ''

handle instance-attribute

handle: Optional[Handle] = None

__init__

__init__()

set_step

set_step(text: str) -> None

promote

promote(key: str, label: str, path: str) -> Handle

The request is slow: show it as an activity (with the step known so far).

request_started

request_started() -> None

A /ui request that may read the database began (see requests_in_flight).

request_done

request_done() -> None

requests_in_flight

requests_in_flight() -> int

How many panel requests run now. A reconnection replaces teradataml's one process-wide connection, so the health monitor must not do it under them: a request cut that way fails with 'NoneType' object has no attribute 'cursor' (seen with several browser sessions).

_describe

_describe(exc) -> str

start

start(key: str, label: str, kind: str = 'job', path: str = '') -> Handle

Register a running job and return its handle. kind is "job" or "request" (an HTTP request still running after a second, see :func:request_activity).

route_label

route_label(path: str) -> str

A readable label for a /ui/... path (the path itself when unknown).

begin_request

begin_request()

Set the current request's state (a ContextVar copied into worker threads). Returns (state, token); pass the token to :func:end_request.

end_request

end_request(state, token, error: Optional[str] = None) -> None

step

step(text: str) -> None

Say what the current request is doing, e.g. activity.step("reading the lineage graph").

Shown in the status bar next to the request. A no-op outside a request (tests, notebooks, background jobs) and never raises. Safe to call from the worker threads of a request.

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).