Bugfix: Harden against lost jobs

This commit is contained in:
Reid 'arrdem' McKenzie 2023-06-03 19:46:26 -06:00
parent dd6f6ac59f
commit 1807eb75dd

View file

@ -12,6 +12,7 @@ import logging
from pathlib import Path from pathlib import Path
from typing import Callable from typing import Callable
from urllib import parse as urlparse from urllib import parse as urlparse
from pprint import pformat
from cherrypy.process.plugins import Monitor from cherrypy.process.plugins import Monitor
from fastmail import FastMailSMTP from fastmail import FastMailSMTP
@ -217,10 +218,7 @@ def pull_jobs(app: App, db: Db) -> None:
except HTTPError: except HTTPError:
printer_state = {"disconnected": True, "error": True} printer_state = {"disconnected": True, "error": True}
if printer_state.get("printing"): if job_state.get("progress", {}).get("completion", 0.0) == 100.0:
pass
elif job_state.get("progress", {}).get("completion", 0.0) == 100.0:
log.info(f"Job {job.id} has succeeded") log.info(f"Job {job.id} has succeeded")
db.finish_job(jid=job.id, state="success") db.finish_job(jid=job.id, state="success")
@ -232,10 +230,14 @@ def pull_jobs(app: App, db: Db) -> None:
log.info(f"Job {job.id} has been acknowledged as cancelled") log.info(f"Job {job.id} has been acknowledged as cancelled")
db.finish_job(jid=job.id, state="cancelled") db.finish_job(jid=job.id, state="cancelled")
if printer_state.get("printing"):
pass
else: else:
log.warn( log.warn(
f"Job {job.id} is in a weird state {job_state.get('progress')!r} {printer_state!r}" f"Job {job.id} is in a weird state; assuming error\n{pformat(job_state.get('progress'))}\n{pformat(printer_state)}"
) )
db.finish_job(jid=job.id, state="failed")
except TimeoutError: except TimeoutError:
pass pass