feat: Queue selection for webhooks (#24876)
* feat: Queue selection for webhooks * fix: code refactor * fix: Add authorization check for get_all_queues * fix(UX): move field to relevant section * refactor: rename field for queue * refactor: simpler autocomplete --------- Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
parent
fe80169287
commit
d66fe5a037
4 changed files with 25 additions and 5 deletions
|
|
@ -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",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue