mirror of
https://github.com/blw1138/Zordon.git
synced 2025-12-17 08:48:13 +00:00
Generate project file hashes on separate thread
This commit is contained in:
@@ -3,6 +3,7 @@ import hashlib
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import threading
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
@@ -13,6 +14,11 @@ logger = logging.getLogger()
|
||||
|
||||
class RenderJob:
|
||||
|
||||
# Get file hash on bg thread
|
||||
def __get_file_hash(self):
|
||||
if os.path.exists(self.worker.input_path):
|
||||
self.file_hash = hashlib.md5(open(self.worker.input_path, 'rb').read()).hexdigest()
|
||||
|
||||
def __init__(self, renderer, input_path, output_path, args, priority=2, owner=None, client=None, notify=None,
|
||||
custom_id=None, name=None):
|
||||
self.id = custom_id or self.generate_id()
|
||||
@@ -28,6 +34,9 @@ class RenderJob:
|
||||
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.file_hash = None
|
||||
threading.Thread(target=self.__get_file_hash).start() # get file hash on bg thread
|
||||
|
||||
def render_status(self):
|
||||
if self.scheduled_start and self.worker.status == RenderStatus.NOT_STARTED:
|
||||
return RenderStatus.SCHEDULED
|
||||
@@ -46,7 +55,7 @@ class RenderJob:
|
||||
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_hash'] = self.file_hash
|
||||
job_dict['percent_complete'] = self.percent_complete()
|
||||
job_dict['file_list'] = self.file_list()
|
||||
job_dict['worker'] = self.worker.__dict__.copy()
|
||||
|
||||
Reference in New Issue
Block a user