Compare commits
2 commits
a4f9af10b5
...
c6ba7bde1f
Author | SHA1 | Date | |
---|---|---|---|
c6ba7bde1f | |||
b9a2ae4274 |
1 changed files with 39 additions and 48 deletions
|
@ -80,7 +80,7 @@ def poll_printers(app: App, db: Db) -> None:
|
||||||
):
|
):
|
||||||
return True # Assume the bed is ready
|
return True # Assume the bed is ready
|
||||||
|
|
||||||
status = client._post(
|
status: dict = client._post(
|
||||||
"/api/plugin/bedready",
|
"/api/plugin/bedready",
|
||||||
json={
|
json={
|
||||||
"command": "check_bed",
|
"command": "check_bed",
|
||||||
|
@ -114,6 +114,8 @@ def poll_printers(app: App, db: Db) -> None:
|
||||||
|
|
||||||
elif printer_state.get("printing"):
|
elif printer_state.get("printing"):
|
||||||
_set_status("running")
|
_set_status("running")
|
||||||
|
if mapped_job:
|
||||||
|
db.start_job(jid=mapped_job.id)
|
||||||
|
|
||||||
elif printer_job.get("state").lower() == "connecting":
|
elif printer_job.get("state").lower() == "connecting":
|
||||||
_set_status("connecting")
|
_set_status("connecting")
|
||||||
|
@ -223,7 +225,6 @@ def revoke_jobs(app: App, db: Db) -> None:
|
||||||
if job.printer_id:
|
if job.printer_id:
|
||||||
printer = db.fetch_printer(pid=job.printer_id)
|
printer = db.fetch_printer(pid=job.printer_id)
|
||||||
|
|
||||||
try:
|
|
||||||
log.info(f"Cancelling running job {job.id}")
|
log.info(f"Cancelling running job {job.id}")
|
||||||
client = get_client(printer.url, printer.api_key)
|
client = get_client(printer.url, printer.api_key)
|
||||||
try:
|
try:
|
||||||
|
@ -237,12 +238,6 @@ def revoke_jobs(app: App, db: Db) -> None:
|
||||||
log.info(f"Job {job.id} -> cancelled")
|
log.info(f"Job {job.id} -> cancelled")
|
||||||
db.finish_job(jid=job.id, state="cancelled")
|
db.finish_job(jid=job.id, state="cancelled")
|
||||||
|
|
||||||
except TimeoutError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
log.exception("Oop")
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info(f"Unmapped job {job.id} became cancelled")
|
log.info(f"Unmapped job {job.id} became cancelled")
|
||||||
db.finish_job(jid=job.id, state="cancelled")
|
db.finish_job(jid=job.id, state="cancelled")
|
||||||
|
@ -253,7 +248,6 @@ def pull_jobs(app: App, db: Db) -> None:
|
||||||
|
|
||||||
for job in db.list_running_jobs():
|
for job in db.list_running_jobs():
|
||||||
printer = db.fetch_printer(pid=job.printer_id)
|
printer = db.fetch_printer(pid=job.printer_id)
|
||||||
try:
|
|
||||||
client = get_client(printer.url, printer.api_key)
|
client = get_client(printer.url, printer.api_key)
|
||||||
job_state = client.job_info()
|
job_state = client.job_info()
|
||||||
try:
|
try:
|
||||||
|
@ -282,12 +276,6 @@ def pull_jobs(app: App, db: Db) -> None:
|
||||||
)
|
)
|
||||||
db.finish_job(jid=job.id, state="failed")
|
db.finish_job(jid=job.id, state="failed")
|
||||||
|
|
||||||
except TimeoutError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
log.exception("Oop")
|
|
||||||
|
|
||||||
|
|
||||||
def send_emails(app, db: Db):
|
def send_emails(app, db: Db):
|
||||||
with closing(
|
with closing(
|
||||||
|
@ -393,5 +381,8 @@ class Worker(Monitor):
|
||||||
)
|
)
|
||||||
|
|
||||||
def callback(self):
|
def callback(self):
|
||||||
|
try:
|
||||||
with closing(self._db_factory(self._app)) as db:
|
with closing(self._db_factory(self._app)) as db:
|
||||||
self._callback(self._app, db)
|
self._callback(self._app, db)
|
||||||
|
except:
|
||||||
|
log.exception("Worker tick failed; exception swallowed")
|
||||||
|
|
Loading…
Reference in a new issue