Add JobNotFoundError and handlers to Flask to cleanup some methods

This commit is contained in:
Brett Williams
2022-12-14 19:04:40 -08:00
parent 2fed26a8a7
commit 285ca3100c
2 changed files with 45 additions and 49 deletions

View File

@@ -16,6 +16,12 @@ JSON_FILE = 'server_state.json'
#todo: move history to sqlite db
class JobNotFoundError(Exception):
def __init__(self, job_id, *args):
super().__init__(args)
self.job_id = job_id
class RenderQueue:
job_queue = []
render_clients = []
@@ -61,8 +67,10 @@ class RenderQueue:
return found_jobs
@classmethod
def job_with_id(cls, job_id):
def job_with_id(cls, job_id, none_ok=False):
found_job = next((x for x in cls.job_queue if x.id == job_id), None)
if not found_job and not none_ok:
raise JobNotFoundError(job_id)
return found_job
@classmethod