From ff0c7f1209cd0ff2d342d29c7c35c17dd2a03d0b Mon Sep 17 00:00:00 2001 From: Sebastian Monroy Date: Thu, 16 Oct 2025 17:52:19 +0100 Subject: [PATCH] feat(nilor-nodes-config): add NILOR_SQS_ENABLED and wire into startup gate - add NILOR_SQS_ENABLED to config.json5 with default false - extend NilorNodesConfig with sqs_enabled; apply env override when allowed - update __init__.py to gate worker startup via cfg.sqs_enabled instead of raw env --- __init__.py | 14 ++++++++------ config/config.json5 | 3 +++ config/config.py | 25 ++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/__init__.py b/__init__.py index 756be79..090a4c3 100644 --- a/__init__.py +++ b/__init__.py @@ -36,18 +36,20 @@ def start_consumer_loop(): asyncio.run(consume_jobs()) -# Start the SQS Worker Consumer (controlled by SQS_ENABLED) -raw_sqs_enabled = os.getenv("SQS_ENABLED", "false") -env_sqs_enabled = raw_sqs_enabled.strip().lower() == "true" -if env_sqs_enabled: +from .config.config import load_nilor_nodes_config + +cfg = load_nilor_nodes_config() + +# Start the SQS Worker Consumer (controlled by NILOR_SQS_ENABLED) +if cfg.sqs_enabled: consumer_thread = threading.Thread(target=start_consumer_loop, daemon=True) consumer_thread.start() print( - f"✅ Nilor-Nodes: SQS worker consumer thread started (SQS_ENABLED={raw_sqs_enabled} in .env)." + "✅ Nilor-Nodes: SQS worker consumer thread started (NILOR_SQS_ENABLED=true)." ) else: print( - f"⚠️ Nilor-Nodes: SQS worker consumer functionality is disabled (SQS_ENABLED={raw_sqs_enabled} in .env)." + "⚠️ Nilor-Nodes: SQS worker consumer functionality is disabled (NILOR_SQS_ENABLED=false)." ) diff --git a/config/config.json5 b/config/config.json5 index 3849fcc..521d4ae 100644 --- a/config/config.json5 +++ b/config/config.json5 @@ -5,6 +5,9 @@ // Required by convention across brain_rnd configs allow_env_override: true, + // Feature flags + NILOR_SQS_ENABLED: false, + // --- Comfy API client (consumed by worker_consumer.py for submissions) --- // Base HTTP URL for ComfyUI REST API (worker submits to `${api_url}/prompt`) NILOR_COMFYUI_API_URL: "http://127.0.0.1:8188", diff --git a/config/config.py b/config/config.py index 0c2f4c8..e9daa41 100644 --- a/config/config.py +++ b/config/config.py @@ -86,6 +86,7 @@ class NilorNodesConfig(BaseConfig): comfy: ComfyApiConfig worker: WorkerConfig allow_env_override: bool + sqs_enabled: bool @classmethod def _get_config_path(cls) -> str: @@ -94,6 +95,7 @@ class NilorNodesConfig(BaseConfig): @classmethod def from_dict(cls, config_dict: Dict[str, object]) -> "NilorNodesConfig": allow_env_override = bool(config_dict.get("allow_env_override", True)) + sqs_enabled = _coerce_bool(config_dict.get("NILOR_SQS_ENABLED", False)) # Build nested from flat NILOR_* keys present in JSON5 comfy_cfg = ComfyApiConfig( @@ -128,7 +130,10 @@ class NilorNodesConfig(BaseConfig): ) cfg = cls( - comfy=comfy_cfg, worker=worker_cfg, allow_env_override=allow_env_override + comfy=comfy_cfg, + worker=worker_cfg, + allow_env_override=allow_env_override, + sqs_enabled=sqs_enabled, ) _validate_comfy_config(cfg.comfy) _validate_worker_config(cfg.worker) @@ -141,6 +146,11 @@ class NilorNodesConfig(BaseConfig): def _apply_env_overrides(cfg: NilorNodesConfig) -> None: if not cfg.allow_env_override: return + + # Feature flags + sqs_enabled = os.getenv("NILOR_SQS_ENABLED", cfg.sqs_enabled) + cfg.sqs_enabled = _coerce_bool(sqs_enabled) + # Comfy cfg.comfy.api_url = os.getenv("NILOR_COMFYUI_API_URL", cfg.comfy.api_url) cfg.comfy.ws_url = os.getenv("NILOR_COMFYUI_WS_URL", cfg.comfy.ws_url) @@ -200,6 +210,19 @@ def _validate_worker_config(cfg: WorkerConfig) -> None: ) +def _coerce_bool(value: object) -> bool: + if isinstance(value, bool): + return value + if value is None: + return False + text = str(value).strip().lower() + if text in {"1", "true", "yes", "on"}: + return True + if text in {"0", "false", "no", "off"}: + return False + return bool(text) + + def _require_url_scheme(url: str, allowed: set[str], key_name: str) -> None: parsed = urlparse(url) if not parsed.scheme or parsed.scheme.lower() not in allowed: