bulk-part-jobs, and scgi retries

This commit is contained in:
Mateusz Gruszczyński
2026-05-04 21:08:30 +02:00
parent d55533d78a
commit 1ff1525f0b
5 changed files with 120 additions and 33 deletions

View File

@@ -236,9 +236,9 @@ def list_jobs(limit: int = 200, offset: int = 0):
def cancel_job(job_id: str) -> bool:
row = _job_row(job_id)
if not row or row["status"] in {"done", "cancelled"}:
if not row or row["status"] not in {"pending", "running"}:
return False
# Awaryjne anulowanie: pending, running i failed można oznaczyć jako cancelled z poziomu użytkownika.
# Note: Emergency cancel ma sens tylko dla niedokonczonych zadan; failed/done zostaja tylko do retry albo czyszczenia logow.
_set_job(job_id, "cancelled", finished=True)
_emit("job_update", {"id": job_id, "status": "cancelled"})
return True
@@ -254,7 +254,7 @@ def emergency_clear_jobs() -> int:
# Awaryjne czyszczenie: najpierw zamyka aktywne zadania jako cancelled, potem czyści całą listę job logów.
now = utcnow()
with connect() as conn:
conn.execute("UPDATE jobs SET status='cancelled', error='Emergency cancelled by user', finished_at=COALESCE(finished_at, ?), updated_at=? WHERE status IN ('pending', 'running', 'failed')", (now, now))
conn.execute("UPDATE jobs SET status='cancelled', error='Emergency cancelled by user', finished_at=COALESCE(finished_at, ?), updated_at=? WHERE status IN ('pending', 'running')", (now, now))
cur = conn.execute("DELETE FROM jobs")
deleted = int(cur.rowcount or 0)
_emit("job_update", {"status": "cleared", "emergency": True})