Skip to content

Commit

Permalink
Skip delayed bounce events
Browse files Browse the repository at this point in the history
Delayed bounce events do not have a message id associated with them, so
we need exception handling. Skip failure events.
  • Loading branch information
ccunningham101 committed Jan 9, 2024
1 parent f2d9d0b commit e51c43d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion retractions/management/commands/retrieve_mailgun_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ def handle(self, *args, **options):

# Loop through them
for i in list(items):
message_id = i["message"]["headers"]["message-id"]
event = i["event"]
try:
message_id = i["message"]["headers"]["message-id"]
except KeyError:
logging.warning(f"{i['event']} has no message id, skipped")
continue
when = datetime.datetime.utcfromtimestamp(i["timestamp"])
url = None
if event == "clicked":
Expand Down Expand Up @@ -109,6 +113,8 @@ def handle(self, *args, **options):
or when > mail_sent.clicked_other
):
mail_sent.clicked_other = when
elif event == "failed":
continue
else:
logging.warning("Unknown event '%s'" % event)

Expand Down

0 comments on commit e51c43d

Please sign in to comment.