Skip to content

Commit

Permalink
chore: update OML not found error msg to include agent
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aga-r committed Dec 6, 2024
1 parent 4935c20 commit 173bcfc
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def queue_ok(agent: str, data: dict) -> None:
{"status": "Queued (Haraka)", "agent": agent, "queue_id": data["queue_id"]},
)

def undelivered(data: dict) -> None:
def undelivered(agent: str, data: dict) -> None:
try:
outgoing_mail_log = data.get("outgoing_mail_log")
queue_id = data["queue_id"]
Expand All @@ -617,7 +617,9 @@ def undelivered(data: dict) -> None:
outgoing_mail_log = frappe.db.exists("Outgoing Mail Log", {"queue_id": queue_id})

if not outgoing_mail_log:
frappe.log_error(title=_("Outgoing Mail Log Not Found"), message=str(data))
frappe.log_error(
title=_("Outgoing Mail Log Not Found - {0}").format(agent), message=str(data)
)
return

doc = frappe.get_doc("Outgoing Mail Log", outgoing_mail_log, for_update=True)
Expand All @@ -643,7 +645,7 @@ def undelivered(data: dict) -> None:
except Exception:
frappe.log_error(title=_("Update Delivery Status - Undelivered"), message=frappe.get_traceback())

def delivered(data: dict) -> None:
def delivered(agent: str, data: dict) -> None:
try:
outgoing_mail_log = data.get("outgoing_mail_log")
queue_id = data["queue_id"]
Expand All @@ -655,7 +657,9 @@ def delivered(data: dict) -> None:
outgoing_mail_log = frappe.db.exists("Outgoing Mail Log", {"queue_id": queue_id})

if not outgoing_mail_log:
frappe.log_error(title=_("Outgoing Mail Log Not Found"), message=str(data))
frappe.log_error(
title=_("Outgoing Mail Log Not Found - {0}").format(agent), message=str(data)
)
return

doc = frappe.get_doc("Outgoing Mail Log", outgoing_mail_log, for_update=True)
Expand Down Expand Up @@ -702,15 +706,16 @@ def delivered(data: dict) -> None:

method, properties, body = result
if body:
app_id = properties.app_id
data = json.loads(body)
hook = data["hook"]

if hook == "queue_ok":
queue_ok(properties.app_id, data)
queue_ok(app_id, data)
elif hook in ["bounce", "deferred"]:
undelivered(data)
undelivered(app_id, data)
elif hook == "delivered":
delivered(data)
delivered(app_id, data)

rmq.channel.basic_ack(delivery_tag=method.delivery_tag)

Expand Down

0 comments on commit 173bcfc

Please sign in to comment.