Skip to content

Commit

Permalink
expose worker_id in jobcontext
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hamdananwar committed Dec 28, 2024
1 parent b190ce0 commit 94d7462
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions livekit-agents/livekit/agents/cli/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def write(self, b: io.BytesIO) -> None:
channel.write_string(b, accept_args.metadata)
channel.write_string(b, running_job.url)
channel.write_string(b, running_job.token)
channel.write_string(b, running_job.worker_id)

channel.write_int(b, self.reload_count)

Expand All @@ -69,6 +70,7 @@ def read(self, b: io.BytesIO) -> None:
job=job,
url=channel.read_string(b),
token=channel.read_string(b),
worker_id=channel.read_string(b),
)
)

Expand Down
2 changes: 2 additions & 0 deletions livekit-agents/livekit/agents/ipc/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def write(self, b: io.BytesIO) -> None:
channel.write_string(b, accept_args.metadata)
channel.write_string(b, self.running_job.url)
channel.write_string(b, self.running_job.token)
channel.write_string(b, self.running_job.worker_id)

def read(self, b: io.BytesIO) -> None:
job = agent.Job()
Expand All @@ -103,6 +104,7 @@ def read(self, b: io.BytesIO) -> None:
job=job,
url=channel.read_string(b),
token=channel.read_string(b),
worker_id=channel.read_string(b),
)


Expand Down
6 changes: 6 additions & 0 deletions livekit-agents/livekit/agents/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class RunningJobInfo:
job: agent.Job
url: str
token: str
worker_id: str


DEFAULT_PARTICIPANT_KINDS: list[rtc.ParticipantKind.ValueType] = [
Expand Down Expand Up @@ -123,6 +124,11 @@ def job(self) -> agent.Job:
"""Returns the current job that the worker is executing."""
return self._info.job

@property
def worker_id(self) -> str:
"""Returns the id of the worker."""
return self._info.worker_id

@property
def room(self) -> rtc.Room:
"""The Room object is the main interface that the worker should interact with.
Expand Down
2 changes: 2 additions & 0 deletions livekit-agents/livekit/agents/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ async def _reload_jobs(self, jobs: list[RunningJobInfo]) -> None:
job=aj.job,
url=url,
token=jwt.encode(decoded, self._opts.api_secret, algorithm="HS256"),
worker_id=aj.worker_id,
)
await self._proc_pool.launch_job(running_info)

Expand Down Expand Up @@ -692,6 +693,7 @@ async def _on_accept(args: JobAcceptArguments) -> None:
job=msg.job,
url=job_assign.url or self._opts.ws_url,
token=job_assign.token,
worker_id=self._id,
)

await self._proc_pool.launch_job(running_info)
Expand Down

0 comments on commit 94d7462

Please sign in to comment.