Skip to main content

Module live

Module live 

Source
Expand description

Live updates for connected dashboard clients.

The dashboard normally runs as its own process (the hammerwork-web binary), apart from the workers. Job lifecycle events published to a worker’s in-process EventManager never reach it, so the dashboard learns about changes from the database they all share: LiveUpdates polls it on an interval and pushes what changed to the WebSocket clients, honouring each client’s subscriptions:

  • a JobUpdate message (event type job_updates) for each job that was created, started, completed, failed or timed out since the previous poll, or that went from Running back to Pending (retried, requeued by the stale job reaper, or released by a batch-mode worker). Those transitions leave no timestamp behind, so the poller tracks the running jobs (up to the per-poll limit) and reads the state of the ones that stopped running;
  • a QueueUpdate message (event type queue_updates) for each queue whose statistics changed.

The work is bounded: nothing is queried while no client is connected, one poll reads at most WebSocketConfig::live_update_max_jobs changed jobs, and the memory of what was already sent only covers a short window.

An application that embeds the dashboard in the same process as its workers can also forward their events directly with forward_job_events, which delivers them without waiting for the next poll.

Structs§

LiveUpdates
Polls the database for job and queue changes and pushes them to WebSocket clients.
PollOutcome
What one poll pushed.

Constants§

POLL_OVERLAP
How far back each poll looks before the previous one, so a change whose transaction committed after that poll ran (with a timestamp from before it) is still seen.

Functions§

forward_job_events
Forward the job lifecycle events of an in-process EventManager subscription to the WebSocket clients subscribed to job_updates, until the event manager is dropped.
job_update_from_event
The JobUpdate sent for a job lifecycle event.