From 562cb23da3b8a8b45a7e5636e19a72b98802c23a Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 28 Feb 2025 19:39:32 -0600 Subject: [PATCH] Feature/112 api version (#119) * Add api_version to status api and server_proxy.py * Add api_version to Zeroconf and filter out incompatible versions when finding available servers * Filter incompatible versions from the UI --- src/api/api_server.py | 6 +++++- src/api/server_proxy.py | 6 +++++- src/distributed_job_manager.py | 10 ++++++---- src/init.py | 4 +++- src/ui/main_window.py | 3 +++ 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/api/api_server.py b/src/api/api_server.py index 4063047..db0cf82 100755 --- a/src/api/api_server.py +++ b/src/api/api_server.py @@ -25,11 +25,13 @@ from src.utilities.config import Config from src.utilities.misc_helper import system_safe_path, current_system_os, current_system_cpu, \ current_system_os_version, num_to_alphanumeric from src.utilities.status_utils import string_to_status +from version import APP_VERSION logger = logging.getLogger() server = Flask(__name__) ssl._create_default_https_context = ssl._create_unverified_context # disable SSL for downloads +API_VERSION = "1" def start_server(hostname=None): @@ -236,7 +238,9 @@ def status(): "memory_percent": psutil.virtual_memory().percent, "job_counts": RenderQueue.job_counts(), "hostname": server.config['HOSTNAME'], - "port": server.config['PORT'] + "port": server.config['PORT'], + "app_version": APP_VERSION, + "api_version": API_VERSION } diff --git a/src/api/server_proxy.py b/src/api/server_proxy.py index e2ba538..efecdbc 100644 --- a/src/api/server_proxy.py +++ b/src/api/server_proxy.py @@ -46,6 +46,7 @@ class RenderServerProxy: self.system_cpu_count = None self.system_os = None self.system_os_version = None + self.system_api_version = None # -------------------------------------------- # Basics / Connection: @@ -100,8 +101,10 @@ class RenderServerProxy: return None def request(self, payload, timeout=5): + from src.api.api_server import API_VERSION hostname = LOOPBACK if self.is_localhost else self.hostname - return requests.get(f'http://{hostname}:{self.port}/api/{payload}', timeout=timeout) + return requests.get(f'http://{hostname}:{self.port}/api/{payload}', timeout=timeout, + headers={"X-API-Version": str(API_VERSION)}) # -------------------------------------------- # Background Updates: @@ -162,6 +165,7 @@ class RenderServerProxy: self.system_cpu_count = status['cpu_count'] self.system_os = status['system_os'] self.system_os_version = status['system_os_version'] + self.system_api_version = status['api_version'] return status # -------------------------------------------- diff --git a/src/distributed_job_manager.py b/src/distributed_job_manager.py index d3cb38a..342c263 100644 --- a/src/distributed_job_manager.py +++ b/src/distributed_job_manager.py @@ -374,13 +374,15 @@ class DistributedJobManager: :param system_os: str, Restrict results to servers running a specific OS :return: A list of dictionaries with each dict containing hostname and cpu_count of available servers """ + from api.api_server import API_VERSION available_servers = [] for hostname in ZeroconfServer.found_hostnames(): host_properties = ZeroconfServer.get_hostname_properties(hostname) - if not system_os or (system_os and system_os == host_properties.get('system_os')): - response = RenderServerProxy(hostname).is_engine_available(engine_name) - if response and response.get('available', False): - available_servers.append(response) + if host_properties.get('api_version') == API_VERSION: + if not system_os or (system_os and system_os == host_properties.get('system_os')): + response = RenderServerProxy(hostname).is_engine_available(engine_name) + if response and response.get('available', False): + available_servers.append(response) return available_servers diff --git a/src/init.py b/src/init.py index e140bb9..2892eba 100644 --- a/src/init.py +++ b/src/init.py @@ -7,6 +7,7 @@ import sys import threading from collections import deque +from api.api_server import API_VERSION from src.api.api_server import start_server from src.api.preview_manager import PreviewManager from src.api.serverproxy_manager import ServerProxyManager @@ -111,7 +112,8 @@ def run(server_only=False) -> int: ZeroconfServer.properties = {'system_cpu': current_system_cpu(), 'system_cpu_cores': multiprocessing.cpu_count(), 'system_os': current_system_os(), - 'system_os_version': current_system_os_version()} + 'system_os_version': current_system_os_version(), + 'api_version': API_VERSION} ZeroconfServer.start() logger.info(f"{APP_NAME} Render Server started - Hostname: {local_hostname}") RenderQueue.start() # Start evaluating the render queue diff --git a/src/ui/main_window.py b/src/ui/main_window.py index cf3ba14..659e70a 100644 --- a/src/ui/main_window.py +++ b/src/ui/main_window.py @@ -16,6 +16,7 @@ from PyQt6.QtWidgets import QMainWindow, QWidget, QHBoxLayout, QListWidget, QTab QTableWidgetItem, QLabel, QVBoxLayout, QHeaderView, QMessageBox, QGroupBox, QPushButton, QListWidgetItem, \ QFileDialog +from api.api_server import API_VERSION from src.render_queue import RenderQueue from src.utilities.misc_helper import get_time_elapsed, resources_dir, is_localhost from src.utilities.status_utils import RenderStatus @@ -412,6 +413,8 @@ class MainWindow(QMainWindow): def update_servers(self): found_servers = list(set(ZeroconfServer.found_hostnames() + self.added_hostnames)) + found_servers = [x for x in found_servers if ZeroconfServer.get_hostname_properties(x)['api_version'] == API_VERSION] + # Always make sure local hostname is first if found_servers and not is_localhost(found_servers[0]): for hostname in found_servers: