-
Notifications
You must be signed in to change notification settings - Fork 31
🐛 Ensure proper Redis client shutdown in Celery #8237
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
Open
giancarloromeo
wants to merge
35
commits into
ITISFoundation:master
Choose a base branch
from
giancarloromeo:is8159/fix-redis-client-lifecycle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
3174045
feat: move redis client lifecycle to app server's one
giancarloromeo ab99e13
fix: remove unused param
giancarloromeo 0d26e0c
fix: fake server Redis client's lifecycle
giancarloromeo f2b84eb
fix: typecheck
giancarloromeo 064f8ac
fix: remove unuseful setup
giancarloromeo f8290e8
fix: celery task manager fixture
giancarloromeo 8999602
fix: task manager property
giancarloromeo dd0a684
fix: typecheck
giancarloromeo a81aafc
fix: absolute import
giancarloromeo d50dbb4
tests: use in-memory Redis
giancarloromeo 86bbe39
fix: rename
giancarloromeo 70bf868
fix: shutdown
giancarloromeo 1f626a2
fix: worker shutdown
giancarloromeo 246d695
fix: use threads
giancarloromeo 41446dc
fix: explicity stop worker
giancarloromeo ee52317
fix: shutdown
giancarloromeo 97ded5f
fix: raise timeout
giancarloromeo abeab74
fix: force worker stop
giancarloromeo 8d2c423
fix: remove rabbit
giancarloromeo 1bb6dad
fix: rabbit
giancarloromeo 9327579
fix: use separate Celery app
giancarloromeo 5198a37
fix: add wait after submit
giancarloromeo f223f79
fix: test indent
giancarloromeo f347698
fix: loglevel
giancarloromeo 585dc9f
fix: wait
giancarloromeo ac35b82
Merge branch 'master' into is8159/fix-redis-client-lifecycle
giancarloromeo ceae3c3
fix: remove partials
giancarloromeo 81161e9
fix: remove unused asserts
giancarloromeo 1e02fe7
fix: assert
giancarloromeo ad4cc8c
fix: remove partial
giancarloromeo 46f5034
remove unused
giancarloromeo fec6e98
rename
giancarloromeo 8d4cf9b
Merge branch 'master' into is8159/fix-redis-client-lifecycle
giancarloromeo 8270bb1
Merge remote-tracking branch 'upstream/master' into is8159/fix-redis-…
giancarloromeo 8125b5d
fix: remove unused
giancarloromeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,24 @@ | |
from fastapi import FastAPI | ||
|
||
from ...celery.app_server import BaseAppServer | ||
from ...celery.task_manager import TaskManager | ||
|
||
_SHUTDOWN_TIMEOUT: Final[float] = datetime.timedelta(seconds=10).total_seconds() | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class FastAPIAppServer(BaseAppServer[FastAPI]): | ||
def __init__(self, app: FastAPI): | ||
super().__init__(app) | ||
self._lifespan_manager: LifespanManager | None = None | ||
@property | ||
def task_manager(self) -> TaskManager: | ||
task_manager = self.app.state.task_manager | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The order in which the app state is setup is very important and here I do not see how this is guaranteed. Can you please show me offline how the workflow works? |
||
assert task_manager, "Task manager is not initialized" # nosec | ||
assert isinstance(task_manager, TaskManager) | ||
return task_manager | ||
|
||
async def lifespan(self, startup_completed_event: threading.Event) -> None: | ||
async def run_until_shutdown( | ||
self, startup_completed_event: threading.Event | ||
) -> None: | ||
async with LifespanManager( | ||
giancarloromeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.app, | ||
startup_timeout=None, # waits for full app initialization (DB migrations, etc.) | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.