Merge pull request #23691 from phot0n/fix-email-bulk-retry

refactor(minor): email retry
This commit is contained in:
Akhil Narang 2024-08-28 16:54:48 +05:30 committed by GitHub
commit cdfbbde3d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 17 deletions

View file

@ -26,13 +26,18 @@ frappe.ui.form.on("Email Queue", {
} else if (frm.doc.status == "Error") {
frm.add_custom_button("Retry Sending", function () {
frm.call({
method: "retry_sending",
doc: frm.doc,
method: "frappe.email.doctype.email_queue.email_queue.retry_sending",
args: {
name: frm.doc.name,
queues: [frm.doc.name],
},
callback: function () {
frm.reload_doc();
frappe.show_alert({
message: __(
"Status Updated. The email will be picked up in the next scheduled run."
),
indicator: "green",
});
},
});
});

View file

@ -222,12 +222,6 @@ class EmailQueue(Document):
.where(email_recipient.creation < (Now() - Interval(days=days)))
).run()
@frappe.whitelist()
def retry_sending(self):
if self.status == "Error":
self.status = "Not Sent"
self.save(ignore_permissions=True)
@task(queue="short")
@deprecated
@ -440,8 +434,9 @@ class SendMailContext:
@frappe.whitelist()
def bulk_retry(queues):
frappe.only_for("System Manager")
def retry_sending(queues: str | list[str]):
if not frappe.has_permission("Email Queue", throw=True):
return
if isinstance(queues, str):
queues = json.loads(queues)
@ -449,11 +444,8 @@ def bulk_retry(queues):
if not queues:
return
frappe.msgprint(
_("Updating Email Queue Statuses. The emails will be picked up in the next scheduled run."),
_("Processing..."),
)
# NOTE: this will probably work fine with the way current listview works (showing and selecting 20-20 records)
# but, ideally this should be enqueued
email_queue = frappe.qb.DocType("Email Queue")
frappe.qb.update(email_queue).set(email_queue.status, "Not Sent").set(email_queue.modified, now()).set(
email_queue.modified_by, frappe.session.user

View file

@ -45,8 +45,15 @@ function show_toggle_sending_button(list_view) {
function add_bulk_retry_button_to_actions(list_view) {
list_view.page.add_actions_menu_item(__("Retry Sending"), () => {
frappe.msgprint(
__(
"Updating Email Queue Statuses. The emails will be picked up in the next scheduled run."
),
__("Processing...")
);
frappe.call({
method: "frappe.email.doctype.email_queue.email_queue.bulk_retry",
method: "frappe.email.doctype.email_queue.email_queue.retry_sending",
args: {
queues: list_view.get_checked_items(true),
},