Compare commits

..

No commits in common. "c6ba7bde1fd391ffa59a76b37d3560d8355af131" and "a4f9af10b5a0408083f014de44e03d19f0ad3cc7" have entirely different histories.

View file

@ -80,7 +80,7 @@ def poll_printers(app: App, db: Db) -> None:
):
return True # Assume the bed is ready
status: dict = client._post(
status = client._post(
"/api/plugin/bedready",
json={
"command": "check_bed",
@ -114,8 +114,6 @@ def poll_printers(app: App, db: Db) -> None:
elif printer_state.get("printing"):
_set_status("running")
if mapped_job:
db.start_job(jid=mapped_job.id)
elif printer_job.get("state").lower() == "connecting":
_set_status("connecting")
@ -225,18 +223,25 @@ def revoke_jobs(app: App, db: Db) -> None:
if job.printer_id:
printer = db.fetch_printer(pid=job.printer_id)
log.info(f"Cancelling running job {job.id}")
client = get_client(printer.url, printer.api_key)
try:
client.cancel()
except HTTPError as e:
if e.response.status_code == 409:
pass
else:
raise
log.info(f"Cancelling running job {job.id}")
client = get_client(printer.url, printer.api_key)
try:
client.cancel()
except HTTPError as e:
if e.response.status_code == 409:
pass
else:
raise
log.info(f"Job {job.id} -> cancelled")
db.finish_job(jid=job.id, state="cancelled")
log.info(f"Job {job.id} -> cancelled")
db.finish_job(jid=job.id, state="cancelled")
except TimeoutError:
pass
except Exception:
log.exception("Oop")
else:
log.info(f"Unmapped job {job.id} became cancelled")
@ -248,33 +253,40 @@ def pull_jobs(app: App, db: Db) -> None:
for job in db.list_running_jobs():
printer = db.fetch_printer(pid=job.printer_id)
client = get_client(printer.url, printer.api_key)
job_state = client.job_info()
try:
printer_state = client.printer().get("state").get("flags", {})
except HTTPError:
printer_state = {"disconnected": True, "error": True}
client = get_client(printer.url, printer.api_key)
job_state = client.job_info()
try:
printer_state = client.printer().get("state").get("flags", {})
except HTTPError:
printer_state = {"disconnected": True, "error": True}
if job_state.get("progress", {}).get("completion", 0.0) == 100.0:
log.info(f"Job {job.id} has succeeded")
db.finish_job(jid=job.id, state="success")
if job_state.get("progress", {}).get("completion", 0.0) == 100.0:
log.info(f"Job {job.id} has succeeded")
db.finish_job(jid=job.id, state="success")
elif printer_state.get("error"):
log.warn(f"Job {job.id} has failed")
db.finish_job(jid=job.id, state="failed")
elif printer_state.get("error"):
log.warn(f"Job {job.id} has failed")
db.finish_job(jid=job.id, state="failed")
elif printer_state.get("cancelling"):
log.info(f"Job {job.id} has been acknowledged as cancelled")
db.finish_job(jid=job.id, state="cancelled")
elif printer_state.get("cancelling"):
log.info(f"Job {job.id} has been acknowledged as cancelled")
db.finish_job(jid=job.id, state="cancelled")
elif printer_state.get("printing"):
db.start_job(jid=job.id)
elif printer_state.get("printing"):
db.start_job(jid=job.id)
else:
log.warn(
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")
else:
log.warn(
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:
pass
except Exception:
log.exception("Oop")
def send_emails(app, db: Db):
@ -381,8 +393,5 @@ class Worker(Monitor):
)
def callback(self):
try:
with closing(self._db_factory(self._app)) as db:
self._callback(self._app, db)
except:
log.exception("Worker tick failed; exception swallowed")
with closing(self._db_factory(self._app)) as db:
self._callback(self._app, db)