Conversation
|
Maybe we can test this idea: start_bg_task()
yield
SIGTERM_RECEIVED.set() # Uvicorn will handle SIGTERM on it's own? https://github.com/fastapi/fastapi/issues/2928Idea behind this:
This will also be a benefit for usual docker installations |
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
28cca00 to
3239525
Compare
|
Yep, from my testing, I think we need to wait for the processing to be done in the lifetime handler to avoid it shutting down prematurely. |
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
|
Added a TASK_POLLOING_INTERVAL setting |
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
|
let's also see what copilot says :D |
There was a problem hiding this comment.
Pull request overview
This PR aims to support Kubernetes pod termination by reacting to shutdown (SIGTERM-driven) and letting the service finish the in-flight task before stopping task polling/processing. It also makes the task polling interval configurable via an environment variable.
Changes:
- Make the task polling interval configurable via
TASK_POLLING_INTERVAL. - Add shutdown coordination between FastAPI lifespan teardown and the background worker thread.
- Document
TASK_POLLING_INTERVALinappinfo/info.xml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/main.py | Adds env-configurable polling and attempts graceful shutdown coordination with the background thread. |
| appinfo/info.xml | Documents the new TASK_POLLING_INTERVAL environment variable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
SIGTERM is used by k8s to signal impending deletion of pods