fix: a crashed job's crash line carries its job id

The bind sat inside the try, so it was already reset when the crash line and the cleanup were logged — the one line most worth finding by job id had none.
This commit is contained in:
2026-09-17 03:53:29 +02:00
parent fac5c4465a
commit 86bc008a81
2 changed files with 43 additions and 7 deletions
+9 -7
View File
@@ -493,14 +493,16 @@ def _worker_loop(idx: int) -> None:
if job_id is None:
_stop.wait(settings.download_poll_seconds)
continue
try:
# Tag every line this job produces (including the crash below) with the job id: a worker
# runs N jobs at once on N threads, so without it the interleaved output is unreadable.
with logs.bind(job_id=job_id):
# Tag every line this job produces (including the crash below) with the job id: a worker runs
# N jobs at once on N threads, so without it the interleaved output is unreadable. The bind
# wraps the handler too — bound inside the `try`, it was already reset by the time the crash
# line was logged.
with logs.bind(job_id=job_id):
try:
_process_job(job_id)
except Exception: # noqa: BLE001
log.exception("processing job %s crashed", job_id)
_fail_running(job_id, error="Worker error", error_code=None)
except Exception: # noqa: BLE001
log.exception("processing job %s crashed", job_id)
_fail_running(job_id, error="Worker error", error_code=None)
def main() -> None: