mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Improved handling of creating job JSONs as well as better handle loading saved JSONs
This commit is contained in:
@@ -45,7 +45,9 @@ class RenderJob:
|
|||||||
try:
|
try:
|
||||||
job_dict = self.__dict__.copy()
|
job_dict = self.__dict__.copy()
|
||||||
job_dict['status'] = self.render_status().value
|
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_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'] = self.worker.__dict__.copy()
|
||||||
job_dict['worker']['status'] = job_dict['status']
|
job_dict['worker']['status'] = job_dict['status']
|
||||||
|
|
||||||
@@ -75,17 +77,35 @@ class RenderJob:
|
|||||||
self.worker.stop()
|
self.worker.stop()
|
||||||
|
|
||||||
def time_elapsed(self):
|
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
|
# calculate elapsed time
|
||||||
elapsed_time = 'Unknown'
|
elapsed_time = None
|
||||||
start_time = self.worker.start_time
|
start_time = self.worker.start_time
|
||||||
end_time = self.worker.end_time
|
end_time = self.worker.end_time
|
||||||
|
|
||||||
if start_time:
|
if start_time:
|
||||||
if end_time:
|
if end_time:
|
||||||
elapsed_time = str(end_time - start_time)
|
elapsed_time = end_time - start_time
|
||||||
elif self.render_status() == RenderStatus.RUNNING:
|
elif self.render_status() == RenderStatus.RUNNING:
|
||||||
elapsed_time = str(datetime.now() - start_time)
|
elapsed_time = datetime.now() - start_time
|
||||||
return elapsed_time
|
|
||||||
|
elapsed_time_string = strfdelta(elapsed_time) if elapsed_time else "Unknown"
|
||||||
|
return elapsed_time_string
|
||||||
|
|
||||||
def frame_count(self):
|
def frame_count(self):
|
||||||
return self.worker.total_frames
|
return self.worker.total_frames
|
||||||
|
|||||||
@@ -106,8 +106,10 @@ class RenderQueue:
|
|||||||
if key in ['date_created']: # convert date strings back to datetime objects
|
if key in ['date_created']: # convert date strings back to datetime objects
|
||||||
render_job.__dict__[key] = datetime.fromisoformat(val)
|
render_job.__dict__[key] = datetime.fromisoformat(val)
|
||||||
else:
|
else:
|
||||||
render_job.__dict__[key] = val
|
import types
|
||||||
render_job.__delattr__('status')
|
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
|
# Handle older loaded jobs that were cancelled before closing
|
||||||
if render_job.render_status() == RenderStatus.RUNNING:
|
if render_job.render_status() == RenderStatus.RUNNING:
|
||||||
@@ -116,7 +118,7 @@ class RenderQueue:
|
|||||||
# finally add back to render queue
|
# finally add back to render queue
|
||||||
cls.job_queue.append(render_job)
|
cls.job_queue.append(render_job)
|
||||||
except Exception as e:
|
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()
|
cls.last_saved_counts = cls.job_counts()
|
||||||
|
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ def generate_thumbnail_for_job(job, thumb_video_path, thumb_image_path, max_widt
|
|||||||
else:
|
else:
|
||||||
source_path = [job.worker.input_path] # use source if nothing else
|
source_path = [job.worker.input_path] # use source if nothing else
|
||||||
|
|
||||||
# Todo: convert image sequence to animated movie
|
if source_path:
|
||||||
valid_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.jpg', '.png', '.exr', '.mxf']
|
# Todo: convert image sequence to animated movie
|
||||||
is_valid_file_type = any(ele in source_path[0] for ele in valid_formats)
|
valid_formats = ['.mp4', '.mov', '.avi', '.mpg', '.mpeg', '.jpg', '.png', '.exr', '.mxf']
|
||||||
if is_valid_file_type and not os.path.exists(thumb_video_path):
|
is_valid_file_type = any(ele in source_path[0] for ele in valid_formats)
|
||||||
save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width)
|
if is_valid_file_type and not os.path.exists(thumb_video_path):
|
||||||
x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],))
|
save_first_frame(source_path=source_path[0], dest_path=thumb_image_path, max_width=max_width)
|
||||||
x.start()
|
x = threading.Thread(target=generate_thumb_thread, args=(source_path[0],))
|
||||||
|
x.start()
|
||||||
|
|||||||
Reference in New Issue
Block a user