fix(server): harden job eviction and worker against missing job id
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,7 @@ def _touch(job: "Job", **changes):
|
||||
|
||||
|
||||
def _evict_if_needed():
|
||||
# Post-condition: len(JOBS) <= _MAX_JOBS (evicts oldest overflow entries).
|
||||
if len(JOBS) <= _MAX_JOBS:
|
||||
return
|
||||
for jid in sorted(JOBS, key=lambda j: JOBS[j].created_at)[: len(JOBS) - _MAX_JOBS]:
|
||||
@@ -50,7 +51,9 @@ def get_job(job_id: str) -> Optional["Job"]:
|
||||
def run_job(job_id: str, fn: Callable[[], dict], done_message: str,
|
||||
fail_message: str = "Something went wrong while fetching.") -> None:
|
||||
def _task():
|
||||
job = JOBS[job_id]
|
||||
job = JOBS.get(job_id)
|
||||
if job is None:
|
||||
return
|
||||
_touch(job, status="running")
|
||||
try:
|
||||
result = fn()
|
||||
|
||||
Reference in New Issue
Block a user