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
This commit is contained in:
Sebastian Monroy
2025-10-16 17:52:19 +01:00
parent 75a632b2e5
commit ff0c7f1209
3 changed files with 35 additions and 7 deletions
+8 -6
View File
@@ -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)."
)
+3
View File
@@ -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",
+24 -1
View File
@@ -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: