Skip to content

Commit

Permalink
Add query graceful shutdown for rolling updates (#10106)
Browse files Browse the repository at this point in the history
* Merge pull request #35 from populationgenomics/add-query-graceful-shutdown

Add query graceful shutdown

* Remove unused argument from query:on_shutdown
  • Loading branch information
illusional authored Mar 18, 2021
1 parent 466f3c3 commit 8e1a9f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions query/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ spec:
app: query
hail.is/sha: "{{ code.sha }}"
spec:
terminationGracePeriodSeconds: 28800 # 8 hours
serviceAccountName: query
{% if deploy %}
priorityClassName: production
Expand Down
10 changes: 10 additions & 0 deletions query/query/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ async def on_cleanup(app):
await asyncio.gather(*(t for t in asyncio.all_tasks() if t is not asyncio.current_task()))


async def on_shutdown(_):
# Filter the asyncio.current_task(), because if we await
# the current task we'll end up in a deadlock
remaining_tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
log.info(f"On shutdown request received, with {len(remaining_tasks)} remaining tasks")
await asyncio.wait(*remaining_tasks)
log.info("All tasks on shutdown have completed")


def run():
app = web.Application()

Expand All @@ -229,6 +238,7 @@ def run():

app.on_startup.append(on_startup)
app.on_cleanup.append(on_cleanup)
app.on_shutdown.append(on_shutdown)

deploy_config = get_deploy_config()
web.run_app(
Expand Down

0 comments on commit 8e1a9f1

Please sign in to comment.