Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/server/server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
"""
task = asyncio.create_task(_remove_old_repositories())

yield # app runs while the background task is alive

task.cancel() # ask the worker to stop
with suppress(asyncio.CancelledError):
await task # swallow the cancellation signal
try:
yield # app runs while the background task is alive
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comments seems redundant, we understand what's going on here.

finally:
task.cancel() # ask the worker to stop
with suppress(asyncio.CancelledError):
await task # swallow the cancellation signal


async def _remove_old_repositories(
Expand Down
Loading