Skip to content

Commit

Permalink
remove module-level ThreadPoolExecutor of events.py
Browse files Browse the repository at this point in the history
(cherry picked from commit 6f6f704)
  • Loading branch information
Belissimo-T committed Sep 28, 2024
1 parent 64acba3 commit 01f9792
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions backend/events.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import concurrent.futures
import dataclasses
import datetime
import logging
import typing

import pymongo
Expand Down Expand Up @@ -117,15 +115,16 @@ def _submit_event(event: Event):
"data": out
}

_COLLECTION.insert_one(entity)
with pymongo.timeout(5):
_COLLECTION.insert_one(entity)


def submit_event(event: Event):
if not shared.mongodb.ENABLED:
logging.debug("MongoDB event collection disabled. Not submitting event.")
return

return _THREAD_POOL_EXECUTOR.submit(_submit_event, event)
_submit_event(event)


_T2 = typing.TypeVar("_T2", bound=Event)
Expand Down Expand Up @@ -173,8 +172,3 @@ def now() -> datetime.datetime:


_COLLECTION = shared.mongodb.DATABASE.get_collection("events") if shared.mongodb.DATABASE is not None else None

if shared.mongodb.ENABLED:
_THREAD_POOL_EXECUTOR = concurrent.futures.ProcessPoolExecutor(max_workers=2)
else:
_THREAD_POOL_EXECUTOR = None

0 comments on commit 01f9792

Please sign in to comment.