Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08b953f40f | ||
|
|
207de4487c | ||
|
|
c36846c008 | ||
|
|
ab7792c8ed | ||
|
|
aa594e80d6 |
@@ -3,6 +3,9 @@ subcategories = {
|
||||
"io": "/IO",
|
||||
}
|
||||
|
||||
import random
|
||||
from datetime import datetime
|
||||
|
||||
from .controllers import CONTROLLER_HOOK
|
||||
|
||||
|
||||
@@ -50,6 +53,83 @@ class NilorUserInput_Int:
|
||||
return (value, None)
|
||||
|
||||
|
||||
class NilorUserInput_Seed:
|
||||
MAX_COMFYUI_SEED = 1125899906842624
|
||||
SEED_RANDOM_STATE = None
|
||||
|
||||
@classmethod
|
||||
def _ensure_seed_random_state(cls):
|
||||
if cls.SEED_RANDOM_STATE is not None:
|
||||
return
|
||||
|
||||
initial_random_state = random.getstate()
|
||||
random.seed(datetime.now().timestamp())
|
||||
cls.SEED_RANDOM_STATE = random.getstate()
|
||||
random.setstate(initial_random_state)
|
||||
|
||||
@classmethod
|
||||
def generate_random_seed(cls):
|
||||
cls._ensure_seed_random_state()
|
||||
|
||||
prev_random_state = random.getstate()
|
||||
random.setstate(cls.SEED_RANDOM_STATE)
|
||||
seed = random.randint(0, cls.MAX_COMFYUI_SEED)
|
||||
cls.SEED_RANDOM_STATE = random.getstate()
|
||||
random.setstate(prev_random_state)
|
||||
return seed
|
||||
|
||||
@classmethod
|
||||
def resolve_seed(cls, value):
|
||||
if value in (None, 0, -1):
|
||||
return cls.generate_random_seed()
|
||||
try:
|
||||
return int(value) % (cls.MAX_COMFYUI_SEED + 1)
|
||||
except (TypeError, ValueError):
|
||||
return cls.generate_random_seed()
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"input_name": (
|
||||
"STRING",
|
||||
{"default": "my_seed_input", "multiline": False},
|
||||
),
|
||||
"value": (
|
||||
"INT",
|
||||
{
|
||||
"default": -1,
|
||||
"min": -1,
|
||||
"max": cls.MAX_COMFYUI_SEED,
|
||||
},
|
||||
),
|
||||
},
|
||||
"hidden": {
|
||||
"prompt": "PROMPT",
|
||||
"extra_pnginfo": "EXTRA_PNGINFO",
|
||||
"unique_id": "UNIQUE_ID",
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("INT", CONTROLLER_HOOK)
|
||||
RETURN_NAMES = ("seed", "_controller_hook")
|
||||
FUNCTION = "get_value"
|
||||
CATEGORY = category + subcategories["io"]
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(
|
||||
cls, input_name, value, prompt=None, extra_pnginfo=None, unique_id=None
|
||||
):
|
||||
# Force node re-execution while using randomize sentinel values.
|
||||
return cls.resolve_seed(value)
|
||||
|
||||
def get_value(
|
||||
self, input_name, value, prompt=None, extra_pnginfo=None, unique_id=None
|
||||
):
|
||||
value = self.resolve_seed(value)
|
||||
return (value, None)
|
||||
|
||||
|
||||
class NilorUserInput_Float:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
@@ -97,6 +177,7 @@ class NilorUserInput_Boolean:
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"NilorUserInput_String": NilorUserInput_String,
|
||||
"NilorUserInput_Int": NilorUserInput_Int,
|
||||
"NilorUserInput_Seed": NilorUserInput_Seed,
|
||||
"NilorUserInput_Float": NilorUserInput_Float,
|
||||
"NilorUserInput_Boolean": NilorUserInput_Boolean,
|
||||
}
|
||||
@@ -104,6 +185,7 @@ NODE_CLASS_MAPPINGS = {
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"NilorUserInput_String": "👺 User Input (String)",
|
||||
"NilorUserInput_Int": "👺 User Input (Int)",
|
||||
"NilorUserInput_Seed": "👺 User Input (Seed)",
|
||||
"NilorUserInput_Float": "👺 User Input (Float)",
|
||||
"NilorUserInput_Boolean": "👺 User Input (Boolean)",
|
||||
}
|
||||
|
||||
+43
-2
@@ -29,6 +29,10 @@ from .config.config import load_nilor_nodes_config, NilorNodesConfig
|
||||
_CFG: NilorNodesConfig = load_nilor_nodes_config()
|
||||
|
||||
|
||||
class JobSubmissionError(Exception):
|
||||
"""Raised when a job cannot be submitted to local ComfyUI."""
|
||||
|
||||
|
||||
class WorkerConsumer:
|
||||
def __init__(self, cfg: NilorNodesConfig):
|
||||
self.session = get_session()
|
||||
@@ -397,7 +401,19 @@ class WorkerConsumer:
|
||||
return
|
||||
|
||||
# Submit to ComfyUI
|
||||
await self._submit_job_to_comfyui(content_id, job_payload)
|
||||
try:
|
||||
await self._submit_job_to_comfyui(content_id, job_payload)
|
||||
except JobSubmissionError as e:
|
||||
logger.error(
|
||||
f"🛑\u2009 Nilor-Nodes (worker_consumer): Submission failed for content_id {content_id}: {e}. Message will be retried/DLQ'd."
|
||||
)
|
||||
await self._emit_failed_status_for_submission_error(
|
||||
content_id=content_id,
|
||||
job_payload=job_payload,
|
||||
error_message=str(e),
|
||||
)
|
||||
# Re-raise so consume_loop does not delete the message.
|
||||
raise
|
||||
|
||||
# Cache context for subsequent status updates
|
||||
try:
|
||||
@@ -418,6 +434,28 @@ class WorkerConsumer:
|
||||
# Re-raise to prevent deletion from queue if we want SQS to handle retry
|
||||
raise
|
||||
|
||||
async def _emit_failed_status_for_submission_error(
|
||||
self, content_id, job_payload, error_message: str
|
||||
):
|
||||
"""Best-effort failed status emission for submit-time errors."""
|
||||
policy = job_payload.get("status_policy") or {}
|
||||
fail_status = policy.get("fail_status", "failed")
|
||||
|
||||
await self._send_status_update(
|
||||
content_id,
|
||||
fail_status,
|
||||
job_payload.get("venue"),
|
||||
job_payload.get("canvas"),
|
||||
job_payload.get("scene"),
|
||||
job_payload.get("job_type"),
|
||||
)
|
||||
logger.info(
|
||||
"ℹ️\u2009 Nilor-Nodes (worker_consumer): Emitted failed status '%s' for content_id %s after submit error: %s",
|
||||
fail_status,
|
||||
content_id,
|
||||
error_message,
|
||||
)
|
||||
|
||||
async def _submit_job_to_comfyui(self, content_id, workflow_data):
|
||||
"""Submits a single job to the ComfyUI API."""
|
||||
try:
|
||||
@@ -484,15 +522,18 @@ class WorkerConsumer:
|
||||
logger.error(
|
||||
f"🛑\u2009 Nilor-Nodes (worker_consumer): Failed to submit job to ComfyUI: {e}. Message will be retried."
|
||||
)
|
||||
raise JobSubmissionError(str(e)) from e
|
||||
except (json.JSONDecodeError, KeyError) as e:
|
||||
logger.error(
|
||||
f"🛑\u2009 Nilor-Nodes (worker_consumer): Failed to parse ComfyUI response: {e}. Discarding malformed response."
|
||||
f"🛑\u2009 Nilor-Nodes (worker_consumer): Failed to parse ComfyUI response: {e}. Message will be retried."
|
||||
)
|
||||
raise JobSubmissionError(f"Malformed ComfyUI response: {e}") from e
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"🛑\u2009 Nilor-Nodes (worker_consumer): An unexpected error occurred while submitting job to ComfyUI: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
raise JobSubmissionError(str(e)) from e
|
||||
|
||||
async def _send_status_update(
|
||||
self, content_id, status, venue=None, canvas=None, scene=None, job_type=None
|
||||
|
||||
Reference in New Issue
Block a user