fix(worker): mark the chosen candidate at download-start, not after success
_mark_chosen ran only after a download succeeded, so throughout the 'downloading' state no candidate was chosen — the Floor row's "source · format · tracks" line was blank (only elapsed showed). Now mark the candidate exclusively at each download attempt so `chosen` reflects the source in flight (and updates on fall-through). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -104,10 +104,12 @@ def _persist_candidates(conn: psycopg.Connection, job_id: str, candidates: list[
|
||||
|
||||
|
||||
def _mark_chosen(conn: psycopg.Connection, job_id: str, source_ref: str) -> None:
|
||||
"""Mark exactly one candidate (the one now being downloaded) as chosen, clearing any
|
||||
prior choice. Called at each download attempt so `chosen` reflects the source in flight."""
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
'UPDATE "Candidate" SET chosen = true WHERE "jobId" = %s AND "sourceRef" = %s',
|
||||
(job_id, source_ref),
|
||||
'UPDATE "Candidate" SET chosen = ("sourceRef" = %s) WHERE "jobId" = %s',
|
||||
(source_ref, job_id),
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
@@ -204,11 +206,11 @@ def run_pipeline(
|
||||
adapter = by_source.get(candidate.source)
|
||||
if adapter is None:
|
||||
continue
|
||||
_mark_chosen(conn, job_id, candidate.source_ref) # reflect the source now in flight
|
||||
shutil.rmtree(staging, ignore_errors=True) # clean slate per attempt
|
||||
result = adapter.download(candidate, staging, lambda _pct: None)
|
||||
if result.ok:
|
||||
winner = candidate
|
||||
_mark_chosen(conn, job_id, candidate.source_ref)
|
||||
break
|
||||
if winner is None or result is None or not result.ok:
|
||||
_fail(conn, job_id, "all downloads failed")
|
||||
|
||||
Reference in New Issue
Block a user