why does the job not shut down immediately on sess...
# ask-ai
f
why does the job not shut down immediately on session
close
event, how to clean up early.
t
Thanks for reaching out, Amjad. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Jobs in LiveKit do not shut down immediately on a session
close
event because the system includes a graceful shutdown mechanism. This allows for cleanup operations to complete before termination. By default, shutdown hooks are given up to 60 seconds to finish their tasks. To clean up early, you can: 1. Register shutdown callbacks for your cleanup logic using
ctx.add_shutdown_callback()
. 2. Trigger the cleanup process explicitly by calling
ctx.shutdown()
in your code. 3. Ensure that your cleanup operations complete within the default timeout period (60 seconds) or adjust the timeout in
WorkerOptions
if necessary. Let me know if you need further clarification or examples! Sources: Inside a session | LiveKit Docs | JobContext | LiveKit Agents | Job lifecycle | LiveKit Docs