chilly-microphone-36803
10/10/2025, 12:35 PMtall-airline-16756
10/10/2025, 12:35 PMtall-airline-16756
10/10/2025, 12:36 PMclose() method to gently shut down the worker, making sure all tasks and resources are properly wrapped up. Here's how you can do it:
await worker.close()
• Draining Workers: If you'd like to stop new jobs but let the current ones finish, the drain() method is perfect. You can even set a timeout like this:
await worker.drain(timeout=1800) # 30 minutes
• Force Termination: In case you need to stop things immediately, you can directly terminate the process like so:
worker.process.terminate()
If you want to dive deeper or have any specific scenarios in mind, just let me know—I’m happy to guide you through it!
Sources: pkg/service/session_manager.go | Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/worker.py | agents/src/worker.ts | Worker options | LiveKit Docschilly-microphone-36803
10/10/2025, 12:54 PMtall-airline-16756
10/10/2025, 12:55 PMlk agent restart command to gracefully stop and restart a worker, which works really well:
lk agent restart --id <agent-id>
Here’s what this command does:
• Stops the worker from accepting any new jobs.
• Lets any active jobs finish up smoothly (this is called draining).
• Then shuts down the worker and starts a fresh instance.
If you have any questions or if there’s a particular situation you’re dealing with, please don’t hesitate to reach out—I’m here to help!
Sources: cmd/lk/agent.go | Agent deployment CLI reference | LiveKit Docs | Worker lifecycle | LiveKit Docs | Log collection | LiveKit Docs | Worker options | LiveKit Docschilly-microphone-36803
10/10/2025, 12:56 PMtall-airline-16756
10/10/2025, 12:56 PMkill <worker-pid>
• For Docker containers, you can use:
docker stop <container-id>
• Graceful Shutdown: This will let the worker finish any active jobs and then shut down within the set timeout (usually 60 seconds).
• Force Kill: If the worker doesn’t respond, you might need to forcefully stop it with SIGKILL:
kill -9 <worker-pid>
• Or for Docker:
docker kill <container-id>
• For AWS ECS: You can scale your service down to zero or update the task definition like this:
aws ecs update-service --cluster <cluster-name> --service <service-name> --desired-count 0
If you have any questions or need a hand with any of these steps, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/worker.py | Job lifecycle | LiveKit Docs | aws-ecs/README.md