rapid-gpu-21466
09/03/2025, 4:07 AMdrain_timeout and gracefull jobs finishing doesn’t make sense for me
I want either:
1. have some kind of event like “drain_started” where I can somehow programmatically ensure I will finish correctly with set timeout
a. there is no such hook exists for a job
2. livekit would force calling shutdown process inside a job after drain_timeout
a. this is clearly not the case as could be seen from “_run.py” implementation: worker.drain raises asyncio.TimeoutError and thus we never proceed to calling worker.aclose()
none of 1 or 2 exists currently in livekit, so just just cant ensure 100% shutdown is going to be called when deploying
am I missing something here?tall-airline-16756
09/03/2025, 4:07 AMtall-airline-16756
09/03/2025, 4:07 AMdrain_timeout, but it doesn’t quite have the exact features you mentioned:
• There isn’t an explicit "drain_started" event that you can use to programmatically confirm job completion within the timeout.
• The drain_timeout won’t automatically force a shutdown. Instead, if the timeout is hit, a WorkerError gets thrown, and it’s up to your application to handle that.
When it comes to the final shutdown, the shutdown_process_timeout parameter controls how long shutdown hooks can run after a job finishes, but this is more about post-processing rather than the initial drain phase.
If you want to chat more or need help setting up a custom solution, just give me a shout—I’m here to help!
Sources: Worker options | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | Job lifecycle | LiveKit Docs | agents/src/worker.ts