Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ServerMessage.termination handler #635

Merged
merged 10 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-zebras-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-agents": patch
---

Add ServerMessage.termination handler
16 changes: 16 additions & 0 deletions livekit-agents/livekit/agents/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ async def _recv_task():
self._handle_availability(msg.availability)
elif which == "assignment":
self._handle_assignment(msg.assignment)
elif which == "termination":
await self._handle_termination(msg.termination)
nbsp marked this conversation as resolved.
Show resolved Hide resolved

tasks = [
asyncio.create_task(_load_task()),
Expand Down Expand Up @@ -615,3 +617,17 @@ def _handle_assignment(self, assignment: agent.JobAssignment):
logger.warning(
"received assignment for an unknown job", extra={"job": assignment.job}
)

async def _handle_termination(self, msg: agent.JobTermination):
proc = next(
(
x
for x in self._proc_pool.processes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should introduce a map<job_id, proc> inside the proc_pool?

if x.running_job and x.running_job.job.id == msg.job_id
),
None,
)
if not proc:
# safe to ignore
return
await proc.aclose()
Loading