build(backend): close the lint gaps the E32 audit measured
ruff gains RUF100, PLW1510 and flake8-bugbear, every hit fixed rather than ignored. B008 stays on with FastAPI's Depends/Query declared immutable. basedpyright moves to standard mode, pytest to --strict-markers, and a hand run of pytest now requires the database unless SIFTLODE_TEST_REQUIRE_DB=0. PLW1510 found a real bug: the three ffprobe probes in plex/stream.py never looked at the exit status, so a probe that failed was read as the file's truth (an HDR source sent down the HW-safe path, a multi-audio file collapsed to one track, a subtitle offset taken from garbage) and the warning each except branch promises never fired. They now run with check=True.
This commit is contained in:
@@ -25,6 +25,7 @@ import threading
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timezone
|
||||
from functools import partial
|
||||
|
||||
from sqlalchemy import text
|
||||
|
||||
@@ -72,7 +73,7 @@ def _wait_for_schema(timeout: float = 300.0) -> bool:
|
||||
with SessionLocal() as db:
|
||||
db.execute(text("SELECT 1 FROM download_jobs LIMIT 1"))
|
||||
return True
|
||||
except Exception: # noqa: BLE001 — table not migrated yet / DB not up yet
|
||||
except Exception: # table not migrated yet / DB not up yet
|
||||
if time.monotonic() > deadline:
|
||||
# The traceback, not `str(exc)[:120]`: this is the last thing the worker says
|
||||
# before it exits, and which driver call failed is the whole question.
|
||||
@@ -366,7 +367,7 @@ def _run_supervised(job_id: int, asset_id: int) -> None:
|
||||
|
||||
try:
|
||||
proc = _spawn_download_child(job_id)
|
||||
except Exception: # noqa: BLE001 — spawn failed; don't leave the asset stuck 'downloading'
|
||||
except Exception: # spawn failed; don't leave the asset stuck 'downloading'
|
||||
log.exception("failed to spawn download child for job %s", job_id)
|
||||
_reset_asset_pending(asset_id)
|
||||
_requeue_if_running(job_id, None)
|
||||
@@ -438,7 +439,7 @@ def _run_supervised(job_id: int, asset_id: int) -> None:
|
||||
cause="child_exit",
|
||||
exit_code=proc.returncode,
|
||||
)
|
||||
except Exception: # noqa: BLE001 — boot recovery is the backstop for a stuck 'running' job
|
||||
except Exception: # boot recovery is the backstop for a stuck 'running' job
|
||||
log.exception("post-exit reconciliation failed for job %s", job_id)
|
||||
return
|
||||
|
||||
@@ -501,6 +502,7 @@ def _process_job(job_id: int) -> None:
|
||||
then run in a supervised CHILD PROCESS (`_run_supervised`) so a wedged yt-dlp/ffmpeg can be
|
||||
hard-killed — a worker THREAD cannot be killed, nor (when it spins in a C call) even
|
||||
cooperatively cancelled, and one such thread starves the others via the GIL."""
|
||||
diagnosis = None # set exactly when the asset has already failed (asset_status == "error")
|
||||
with SessionLocal() as db:
|
||||
job = db.get(DownloadJob, job_id)
|
||||
if job is None:
|
||||
@@ -528,7 +530,7 @@ def _process_job(job_id: int) -> None:
|
||||
if asset_status == "ready":
|
||||
_finish_from_cache(job_id, asset_id)
|
||||
return
|
||||
if asset_status == "error":
|
||||
if diagnosis is not None:
|
||||
_fail_running(
|
||||
job_id,
|
||||
error=asset_error or "Download failed",
|
||||
@@ -577,7 +579,7 @@ def _worker_loop(idx: int) -> None:
|
||||
while not _stop.is_set():
|
||||
try:
|
||||
job_id = _claim_job()
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
log.exception("claim failed")
|
||||
_stop.wait(settings.download_poll_seconds)
|
||||
continue
|
||||
@@ -597,12 +599,12 @@ def _worker_loop(idx: int) -> None:
|
||||
job_id,
|
||||
exc,
|
||||
"crash",
|
||||
lambda: _fail_running(job_id, error="Worker error", error_code=None),
|
||||
partial(_fail_running, job_id, error="Worker error", error_code=None),
|
||||
)
|
||||
# silent-ok: not silent — `_report_worker_error` logged the crash before this
|
||||
# re-raise. Failing the job hit the database, and letting that out would end this
|
||||
# worker thread for good; boot recovery settles a job left `running`.
|
||||
except Exception: # noqa: BLE001
|
||||
except Exception:
|
||||
log.exception(
|
||||
"could not fail job %s after its crash",
|
||||
job_id,
|
||||
|
||||
Reference in New Issue
Block a user