Skip to content

Commit

Permalink
fix 6f6f704: add try/except around event insertion
Browse files Browse the repository at this point in the history
(cherry picked from commit c69c03e)
  • Loading branch information
Belissimo-T committed Sep 28, 2024
1 parent 769dc04 commit 4dbab54
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions backend/events.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dataclasses
import datetime
import logging
import typing

import pymongo
import pymongo.errors

import shared.mongodb

Expand Down Expand Up @@ -115,8 +116,14 @@ def _submit_event(event: Event):
"data": out
}

with pymongo.timeout(5):
_COLLECTION.insert_one(entity)
try:
with pymongo.timeout(5):
_COLLECTION.insert_one(entity)
except pymongo.errors.PyMongoError as e:
if e.timeout:
logging.getLogger(__name__).warning("MongoDB event submission timed out.")
else:
logging.getLogger(__name__).exception("MongoDB event submission failed.")


def submit_event(event: Event):
Expand Down

0 comments on commit 4dbab54

Please sign in to comment.