diff --git a/frappe/integrations/doctype/webhook/__init__.py b/frappe/integrations/doctype/webhook/__init__.py index 9cbab711ab..4538853386 100644 --- a/frappe/integrations/doctype/webhook/__init__.py +++ b/frappe/integrations/doctype/webhook/__init__.py @@ -8,7 +8,7 @@ def get_all_webhooks(): # query webhooks webhooks_list = frappe.get_all( "Webhook", - fields=["name", "condition", "webhook_docevent", "webhook_doctype"], + fields=["name", "condition", "webhook_docevent", "webhook_doctype", "background_jobs_queue"], filters={"enabled": True}, ) @@ -104,4 +104,5 @@ def flush_webhook_execution_queue(): doc=instance.doc, webhook=instance.webhook, now=frappe.flags.in_test, + queue=instance.webhook.background_jobs_queue or "default", ) diff --git a/frappe/integrations/doctype/webhook/webhook.js b/frappe/integrations/doctype/webhook/webhook.js index a1a2f02abc..9fad6150ab 100644 --- a/frappe/integrations/doctype/webhook/webhook.js +++ b/frappe/integrations/doctype/webhook/webhook.js @@ -81,6 +81,10 @@ frappe.webhook = { frappe.ui.form.on("Webhook", { refresh: (frm) => { frappe.webhook.set_fieldname_select(frm); + frm.set_query( + "background_jobs_queue", + "frappe.integrations.doctype.webhook.webhook.get_all_queues" + ); }, request_structure: (frm) => { diff --git a/frappe/integrations/doctype/webhook/webhook.json b/frappe/integrations/doctype/webhook/webhook.json index 47edb8a401..a4d924fc6f 100644 --- a/frappe/integrations/doctype/webhook/webhook.json +++ b/frappe/integrations/doctype/webhook/webhook.json @@ -17,8 +17,9 @@ "html_condition", "sb_webhook", "request_url", - "timeout", "is_dynamic_url", + "timeout", + "background_jobs_queue", "cb_webhook", "request_method", "request_structure", @@ -211,8 +212,12 @@ "description": "The number of seconds until the request expires", "fieldname": "timeout", "fieldtype": "Int", - "label": "Request Timeout", - "reqd": 1 + "label": "Request Timeout" + }, + { + "fieldname": "background_jobs_queue", + "fieldtype": "Autocomplete", + "label": "Background Jobs Queue" } ], "links": [ @@ -221,7 +226,7 @@ "link_fieldname": "webhook" } ], - "modified": "2024-02-05 17:49:50.203001", + "modified": "2024-02-19 11:40:58.387233", "modified_by": "Administrator", "module": "Integrations", "name": "Webhook", diff --git a/frappe/integrations/doctype/webhook/webhook.py b/frappe/integrations/doctype/webhook/webhook.py index 7aad3da182..a425537be7 100644 --- a/frappe/integrations/doctype/webhook/webhook.py +++ b/frappe/integrations/doctype/webhook/webhook.py @@ -13,6 +13,7 @@ import requests import frappe from frappe import _ from frappe.model.document import Document +from frappe.utils.background_jobs import get_queues_timeout from frappe.utils.jinja import validate_template from frappe.utils.safe_exec import get_safe_globals @@ -30,6 +31,7 @@ class Webhook(Document): from frappe.integrations.doctype.webhook_header.webhook_header import WebhookHeader from frappe.types import DF + background_jobs_queue: DF.Autocomplete | None condition: DF.SmallText | None enable_security: DF.Check enabled: DF.Check @@ -252,3 +254,11 @@ def get_webhook_data(doc, webhook): data = json.loads(data) return data + + +@frappe.whitelist() +def get_all_queues(): + """Fetches all workers and returns a list of available queue names.""" + frappe.only_for("System Manager") + + return get_queues_timeout().keys()