Improved handling of creating job JSONs as well as better handle loading saved JSONs

This commit is contained in:
Brett Williams
2022-12-14 10:49:18 -08:00
parent 9a9b0304b9
commit 455934daa1
3 changed files with 37 additions and 14 deletions

View File

@@ -45,7 +45,9 @@ class RenderJob:
try:
job_dict = self.__dict__.copy()
job_dict['status'] = self.render_status().value
job_dict['time_elapsed'] = self.time_elapsed() if type(self.time_elapsed) != str else self.time_elapsed
job_dict['file_hash'] = self.file_hash if self.file_hash and isinstance(self.file_hash, str) else self.file_hash()
job_dict['file_list'] = self.file_list()
job_dict['worker'] = self.worker.__dict__.copy()
job_dict['worker']['status'] = job_dict['status']
@@ -75,17 +77,35 @@ class RenderJob:
self.worker.stop()
def time_elapsed(self):
from string import Template
class DeltaTemplate(Template):
delimiter = "%"
def strfdelta(tdelta, fmt='%H:%M:%S'):
d = {"D": tdelta.days}
hours, rem = divmod(tdelta.seconds, 3600)
minutes, seconds = divmod(rem, 60)
d["H"] = '{:02d}'.format(hours)
d["M"] = '{:02d}'.format(minutes)
d["S"] = '{:02d}'.format(seconds)
t = DeltaTemplate(fmt)
return t.substitute(**d)
# calculate elapsed time
elapsed_time = 'Unknown'
elapsed_time = None
start_time = self.worker.start_time
end_time = self.worker.end_time
if start_time:
if end_time:
elapsed_time = str(end_time - start_time)
elapsed_time = end_time - start_time
elif self.render_status() == RenderStatus.RUNNING:
elapsed_time = str(datetime.now() - start_time)
return elapsed_time
elapsed_time = datetime.now() - start_time
elapsed_time_string = strfdelta(elapsed_time) if elapsed_time else "Unknown"
return elapsed_time_string
def frame_count(self):
return self.worker.total_frames

View File

@@ -106,8 +106,10 @@ class RenderQueue:
if key in ['date_created']: # convert date strings back to datetime objects
render_job.__dict__[key] = datetime.fromisoformat(val)
else:
render_job.__dict__[key] = val
render_job.__delattr__('status')
import types
if hasattr(render_job, key):
if getattr(render_job, key) and not isinstance(getattr(render_job, key), types.MethodType):
render_job.__dict__[key] = val
# Handle older loaded jobs that were cancelled before closing
if render_job.render_status() == RenderStatus.RUNNING:
@@ -116,7 +118,7 @@ class RenderQueue:
# finally add back to render queue
cls.job_queue.append(render_job)
except Exception as e:
logger.error(f"Unable to load job: {job} - {e}")
logger.exception(f"Unable to load job: {job['id']} - {e}")
cls.last_saved_counts = cls.job_counts()

View File

@@ -33,10 +33,11 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt
else:
source_path = [job.worker.input_path] # use source if nothing else
# Todo: convert image sequence to animated movie
valid_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.jpg', '.png', '.exr', '.mxf']
is_valid_file_type = any(ele in source_path[0] for ele in valid_formats)
if is_valid_file_type and not os.path.exists(thumb_video_path):
save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width)
x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],))
x.start()
if source_path:
# Todo: convert image sequence to animated movie
valid_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.jpg', '.png', '.exr', '.mxf']
is_valid_file_type = any(ele in source_path[0] for ele in valid_formats)
if is_valid_file_type and not os.path.exists(thumb_video_path):
save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width)
x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],))
x.start()