the current approach with `drain_timeout` and grac...
# ask-ai
r
the current approach with
drain_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?
t
Thanks for reaching out, Stanislav. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just to clarify, LiveKit does offer a draining mechanism with a configurable
drain_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