Add sync db sessionmaker for Celery tasks#120
Open
szyszkapiotr wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue: #121
In my previous MR (#108) we have migrated from sync to async SQLAlchemy sessions. That fits the API layer very well (FastAPI is async-first), but async sessions may cause problems in a purely synchronous context — namely inside Celery tasks. For that specific case I propose using sync db sessions, since running anything async inside Celery is famously painful.
This MR adds a sync db sessionmaker and lays out how to handle database operations inside Celery tasks. Rule of thumb:
asyncio.run.In this MR:
app/database.py;AGENTS.md) to describe the approach above;app/integrations/celery/tasks/dummy_task.py).