-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switching background tasks for threads on client and server updates #122
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #122 +/- ##
==========================================
+ Coverage 89.85% 93.99% +4.14%
==========================================
Files 23 24 +1
Lines 2129 2166 +37
Branches 179 120 -59
==========================================
+ Hits 1913 2036 +123
+ Misses 216 130 -86 ☔ View full report in Codecov by Sentry. |
""" | ||
LOGGER.info(f"Starting listener for client messages from job {job.id} at channel {client_info.uuid}") | ||
|
||
assert client_info.uuid is not None, "client_info.uuid is None." | ||
|
||
db_client: AsyncIOMotorClient[Any] = AsyncIOMotorClient(MONGODB_URI) | ||
database = db_client[DATABASE_NAME] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is sort of an interesting structure that I'm not super familiar with. For my own curiosity, what is happening when you do db_client[DATABASE_NAME]
? I've only ever seen [...] for generics in mypy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah...this was probably a dumb question. I assume this is something like a map that retrieves the database from the key 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting thing, I went a bit deep into that because I had to figure out how to mock it for unit tests haha. It is not a map/dictionary, it's actually a class that implements the __getitem__
function, which makes it also behave like a dictionary. I guess they thought it's a bit cleaner to do that than to implement a get_database
kind of method but it makes it a bit confusing at first. At least I learned something :)
See:
mock_db_client.__getitem__ = Mock( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha...very similar, but much less obvious what's happening 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look good to me. I'm definitely not an expert in database communication, but the threading change seems fairly straightforward.
PR Type
Fix
Short Description
Clickup Ticket(s): NA
While I was testing the app this week, I realized FastAPI's Background Tasks, which we use for client and server metric updates, are not really suitable for long running tasks as they are executed serially instead of in parallel.
Here I am switching from that to plain python threads, and also making a few other changes:
Tests Added
Fixed unit and integration tests accordingly