-
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
base: master
Are you sure you want to change the base?
Changes from 24 commits
3174045
ab99e13
0d26e0c
f2b84eb
064f8ac
f8290e8
8999602
dd0a684
a81aafc
d50dbb4
86bbe39
70bf868
1f626a2
246d695
41446dc
ee52317
97ded5f
abeab74
8d2c423
1bb6dad
9327579
5198a37
f223f79
f347698
585dc9f
ac35b82
ceae3c3
81161e9
1e02fe7
ad4cc8c
46f5034
fec6e98
8d4cf9b
8270bb1
8125b5d
59c33ae
7618c5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,12 @@ def shutdown_event(self) -> asyncio.Event: | |
return self._shutdown_event | ||
|
||
@property | ||
@abstractmethod | ||
def task_manager(self) -> TaskManager: | ||
return self._task_manager | ||
|
||
@task_manager.setter | ||
def task_manager(self, manager: TaskManager) -> None: | ||
self._task_manager = manager | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
async def lifespan( | ||
async def start_and_hold( | ||
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. check my other comment about renaming this 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. for interfaces, plaease add some doc about what is expected, specially |
||
self, | ||
startup_completed_event: threading.Event, | ||
) -> None: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
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() | ||
|
||
|
@@ -18,7 +19,13 @@ def __init__(self, app: FastAPI): | |
super().__init__(app) | ||
self._lifespan_manager: LifespanManager | None = None | ||
|
||
async def lifespan(self, startup_completed_event: threading.Event) -> None: | ||
@property | ||
def task_manager(self) -> TaskManager: | ||
assert self.app.state.task_manager, "Task manager is not initialized" # nosec | ||
task_manager: TaskManager = self.app.state.task_manager | ||
giancarloromeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return task_manager | ||
|
||
async def start_and_hold(self, startup_completed_event: threading.Event) -> None: | ||
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. it is a lifespan and the one problem I see here is the returned type that is wrong. It should be 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. We don't 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. Since this is the primary entrypoint for this service, i would call it Regarding @sanderegg comment. In other parts of the code our approach is to provide a context-manager like function that includes setup&tear-down parts in one place (see https://github.com/ITISFoundation/osparc-simcore/blob/master/packages/service-library/src/servicelib/fastapi/postgres_lifespan.py#L31C11-L31C37). This approach here is difference since this member function encapsulates the setup&tear-down parts AND runs it. That reduces the flexibility but I guess you do not need it here. I understand this function also can only be called once. Therefore I would add a protection for it 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. TIP: use |
||
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.) | ||
|
Uh oh!
There was an error while loading. Please reload this page.