Job submission code and API cleanup (#127)

* Refactor add jobs and make add_job api only be one job (instead of a list)

* Renamed to JobImportHandler and misc cleanup

* Dont bury exceptions in server proxy post_job

* Update code to create child jobs in a cleaner manner
This commit is contained in:
2025-12-31 23:14:28 -06:00
committed by GitHub
parent e335328530
commit d8af7c878e
10 changed files with 267 additions and 357 deletions

View File

@@ -2,10 +2,8 @@ import logging
import multiprocessing
import os
import socket
import sys
import threading
import cpuinfo
import psutil
from src.api.api_server import API_VERSION
@@ -19,7 +17,7 @@ from src.utilities.config import Config
from src.utilities.misc_helper import (get_gpu_info, system_safe_path, current_system_cpu, current_system_os,
current_system_os_version, current_system_cpu_brand, check_for_updates)
from src.utilities.zeroconf_server import ZeroconfServer
from src.version import APP_NAME, APP_VERSION, APP_REPO_NAME, APP_REPO_OWNER
from src.version import APP_NAME, APP_VERSION
logger = logging.getLogger()
@@ -45,12 +43,8 @@ class ZordonServer:
PreviewManager.storage_path = system_safe_path(
os.path.join(os.path.expanduser(Config.upload_folder), 'previews'))
# Debug info
logger.debug(f"Upload directory: {os.path.expanduser(Config.upload_folder)}")
logger.debug(f"Thumbs directory: {PreviewManager.storage_path}")
logger.debug(f"Engines directory: {EngineManager.engines_path}")
self.api_server = None
self.server_hostname = None
def start_server(self):
@@ -77,22 +71,25 @@ class ZordonServer:
raise ProcessLookupError(err_msg)
# main start
logger.info(f"Starting {APP_NAME} Render Server")
logger.info(f"Starting {APP_NAME} Render Server ({APP_VERSION})")
logger.debug(f"Upload directory: {os.path.expanduser(Config.upload_folder)}")
logger.debug(f"Thumbs directory: {PreviewManager.storage_path}")
logger.debug(f"Engines directory: {EngineManager.engines_path}")
# Set up the RenderQueue object
RenderQueue.load_state(database_directory=system_safe_path(os.path.expanduser(Config.upload_folder)))
ServerProxyManager.subscribe_to_listener()
DistributedJobManager.subscribe_to_listener()
# get hostname
local_hostname = socket.gethostname()
self.server_hostname = socket.gethostname()
# configure and start API server
self.api_server = threading.Thread(target=start_api_server, args=(local_hostname,))
self.api_server = threading.Thread(target=start_api_server, args=(self.server_hostname,))
self.api_server.daemon = True
self.api_server.start()
# start zeroconf server
ZeroconfServer.configure(f"_{APP_NAME.lower()}._tcp.local.", local_hostname, Config.port_number)
ZeroconfServer.configure(f"_{APP_NAME.lower()}._tcp.local.", self.server_hostname, Config.port_number)
ZeroconfServer.properties = {'system_cpu': current_system_cpu(),
'system_cpu_brand': current_system_cpu_brand(),
'system_cpu_cores': multiprocessing.cpu_count(),
@@ -102,7 +99,7 @@ class ZordonServer:
'gpu_info': get_gpu_info(),
'api_version': API_VERSION}
ZeroconfServer.start()
logger.info(f"{APP_NAME} Render Server started - Hostname: {local_hostname}")
logger.info(f"{APP_NAME} Render Server started - Hostname: {self.server_hostname}")
RenderQueue.start() # Start evaluating the render queue
def is_running(self):
@@ -125,6 +122,6 @@ if __name__ == '__main__':
except KeyboardInterrupt:
pass
except Exception as e:
logger.error(f"Unhandled exception: {e}")
logger.fatal(f"Unhandled exception: {e}")
finally:
server.stop_server()