From c587ede2dca28b83428b932340df54115dd30441 Mon Sep 17 00:00:00 2001 From: Royce Schultz Date: Tue, 22 Apr 2025 19:40:27 -0600 Subject: [PATCH] Adds empty queue mode to webhook notification. --- nodes/webhook.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nodes/webhook.py b/nodes/webhook.py index 3d72ee4..0a8d9be 100644 --- a/nodes/webhook.py +++ b/nodes/webhook.py @@ -1,5 +1,6 @@ import requests import json +from server import PromptServer from .util import ComfyAnyType @@ -9,7 +10,7 @@ class Webhook: return { "required": { "any": (ComfyAnyType("*"), {}), - # "mode": (["always", "on empty queue"], {}), # TODO: Need a way to get queue status from main.py + "mode": (["always", "on empty queue"], {}), "webhook_url": ("STRING", {'default': 'http://localhost:5000/'}), "verify_ssl": ("BOOLEAN", {"default": True}), "notification_text": ('STRING', {'default': 'Your notification has triggered.'}), @@ -23,8 +24,13 @@ class Webhook: RETURN_TYPES = tuple() CATEGORY = "notifications" - def hook(self, any, webhook_url, notification_text, json_format, timeout, verify_ssl): - + def hook(self, any, mode, webhook_url, notification_text, json_format, timeout, verify_ssl): + if mode == 'on empty queue': + queue = PromptServer.instance.prompt_queue.queue + queue_len = len(queue) + if queue_len > 0: + print(f'[Webhook Notificaton] Not sending notification, queue is not empty (size: {queue_len})') + return (0, ) payload = json_format.replace("", notification_text) payload = json.loads(payload) res = requests.post(webhook_url, json=payload, timeout=timeout, verify=verify_ssl)