Generic background worker (phase 0, step 2)
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Failing after 38s
CI / test (push) Successful in 46s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s

scrobbler/worker.py runs tasks that modules register: queue tasks
(called while they report work) and periodic tasks. A failing task is
logged, counted, rolled back and doesn't stop the others. Imports are
now just a registered task plus a periodic stall check.

- `flask worker` replaces `flask imports worker` (kept as an alias);
  compose uses the new command
- scrobbler_worker_tasks_total{task,outcome} and a Worker tasks panel
  on the Usage dashboard
- WORKER_METRICS_PORT (IMPORT_WORKER_METRICS_PORT still honoured)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 19:57:25 +01:00
1 parent 59ff1bdfa0
commit 098eab025f
13 files changed
+292 -42

No files matched your search

+16 -12
View File
@@ -569,15 +569,19 @@ def _finish(job: ImportJob, status: str, error: str | None = None) -> None:
events.send(events.import_finished, db.session.get(User, job.user_id), job=job)
def run_worker(poll_seconds: float = 2.0, once: bool = False) -> None:
requeue_stalled()
while True:
job = claim_next_job()
if job is not None:
log.info("import job %s (%s) for user %s started", job.id, job.source, job.user_id)
process_job(job)
log.info("import job %s finished: %s", job.id, job.status)
continue
if once:
return
time.sleep(poll_seconds)
def work_once() -> bool:
"""Worker task: process the oldest waiting import, if any."""
job = claim_next_job()
if job is None:
return False
log.info("import job %s (%s) for user %s started", job.id, job.source, job.user_id)
process_job(job)
log.info("import job %s finished", job.id)
return True
def register_worker_tasks() -> None:
from scrobbler import worker
worker.register_task("imports", work_once)
worker.register_periodic("imports.requeue_stalled", 60, requeue_stalled)