mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Improve job management. Remove archived flag.
This commit is contained in:
@@ -22,7 +22,7 @@ server = Flask(__name__)
|
|||||||
|
|
||||||
@server.get('/jobs')
|
@server.get('/jobs')
|
||||||
def jobs_json():
|
def jobs_json():
|
||||||
return [x.json_safe_copy() for x in RenderQueue.job_queue if not x.archived]
|
return [x.json_safe_copy() for x in RenderQueue.job_queue]
|
||||||
|
|
||||||
|
|
||||||
@server.get('/jobs/<status_val>')
|
@server.get('/jobs/<status_val>')
|
||||||
@@ -130,7 +130,7 @@ def full_status():
|
|||||||
@server.get('/snapshot')
|
@server.get('/snapshot')
|
||||||
def snapshot():
|
def snapshot():
|
||||||
server_status = RenderQueue.status()
|
server_status = RenderQueue.status()
|
||||||
server_jobs = [x.json_safe_copy() for x in RenderQueue.job_queue if not x.archived]
|
server_jobs = [x.json_safe_copy() for x in RenderQueue.job_queue]
|
||||||
server_data = {'status': server_status, 'jobs': server_jobs, 'timestamp': datetime.now().isoformat()}
|
server_data = {'status': server_status, 'jobs': server_jobs, 'timestamp': datetime.now().isoformat()}
|
||||||
return server_data
|
return server_data
|
||||||
|
|
||||||
@@ -270,7 +270,6 @@ def cancel_job():
|
|||||||
else:
|
else:
|
||||||
found = [x for x in RenderQueue.job_queue if x.id == job_id]
|
found = [x for x in RenderQueue.job_queue if x.id == job_id]
|
||||||
if len(found) > 1:
|
if len(found) > 1:
|
||||||
# logger.error('Multiple jobs found for ID {}'.format(job_id))
|
|
||||||
return f'multiple jobs found for ID {job_id}', 400
|
return f'multiple jobs found for ID {job_id}', 400
|
||||||
elif found:
|
elif found:
|
||||||
success = RenderQueue.cancel_job(found[0])
|
success = RenderQueue.cancel_job(found[0])
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ class RenderJob:
|
|||||||
self.scheduled_start = None
|
self.scheduled_start = None
|
||||||
self.renderer = renderer
|
self.renderer = renderer
|
||||||
self.name = name or os.path.basename(input_path) + '_' + self.date_created.isoformat()
|
self.name = name or os.path.basename(input_path) + '_' + self.date_created.isoformat()
|
||||||
self.archived = False
|
|
||||||
|
|
||||||
self.worker = RenderWorkerFactory.create_worker(renderer, input_path, output_path, args)
|
self.worker = RenderWorkerFactory.create_worker(renderer, input_path, output_path, args)
|
||||||
self.worker.log_path = os.path.join(os.path.dirname(input_path), self.name + '.log')
|
self.worker.log_path = os.path.join(os.path.dirname(input_path), self.name + '.log')
|
||||||
@@ -35,7 +34,9 @@ class RenderJob:
|
|||||||
return self.worker.status
|
return self.worker.status
|
||||||
|
|
||||||
def file_hash(self):
|
def file_hash(self):
|
||||||
return hashlib.md5(open(self.worker.input_path, 'rb').read()).hexdigest()
|
if os.path.exists(self.worker.input_path):
|
||||||
|
return hashlib.md5(open(self.worker.input_path, 'rb').read()).hexdigest()
|
||||||
|
return None
|
||||||
|
|
||||||
def json_safe_copy(self):
|
def json_safe_copy(self):
|
||||||
"""Converts RenderJob into JSON-friendly dict"""
|
"""Converts RenderJob into JSON-friendly dict"""
|
||||||
|
|||||||
@@ -56,10 +56,8 @@ class RenderQueue:
|
|||||||
return pending_jobs
|
return pending_jobs
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def jobs_with_status(cls, status, priority_sorted=False, include_archived=True):
|
def jobs_with_status(cls, status, priority_sorted=False):
|
||||||
found_jobs = [x for x in cls.job_queue if x.render_status() == status]
|
found_jobs = [x for x in cls.job_queue if x.render_status() == status]
|
||||||
if not include_archived:
|
|
||||||
found_jobs = [x for x in found_jobs if not x.archived]
|
|
||||||
if priority_sorted:
|
if priority_sorted:
|
||||||
found_jobs = sorted(found_jobs, key=lambda a: a.priority, reverse=False)
|
found_jobs = sorted(found_jobs, key=lambda a: a.priority, reverse=False)
|
||||||
return found_jobs
|
return found_jobs
|
||||||
@@ -73,8 +71,8 @@ class RenderQueue:
|
|||||||
def clear_history(cls):
|
def clear_history(cls):
|
||||||
to_remove = [x for x in cls.job_queue if x.render_status() in [RenderStatus.CANCELLED,
|
to_remove = [x for x in cls.job_queue if x.render_status() in [RenderStatus.CANCELLED,
|
||||||
RenderStatus.COMPLETED, RenderStatus.ERROR]]
|
RenderStatus.COMPLETED, RenderStatus.ERROR]]
|
||||||
for x in to_remove:
|
for job_to_remove in to_remove:
|
||||||
x.archived = True
|
cls.job_queue.remove(job_to_remove)
|
||||||
cls.save_state()
|
cls.save_state()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -204,11 +202,6 @@ class RenderQueue:
|
|||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def all_jobs(cls):
|
|
||||||
all_jobs = [x for x in cls.job_queue if not x.archived]
|
|
||||||
return all_jobs
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register_client(cls, hostname):
|
def register_client(cls, hostname):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user