MCPcopy
hub / github.com/livekit/livekit / DeleteAgentDispatch

Method DeleteAgentDispatch

pkg/rtc/room.go:902–952  ·  view source on GitHub ↗
(dispatchID string)

Source from the content-addressed store, hash-verified

900}
901
902func (r *Room) DeleteAgentDispatch(dispatchID string) (*livekit.AgentDispatch, error) {
903 r.lock.Lock()
904 ad := r.agentDispatches[dispatchID]
905 if ad == nil {
906 r.lock.Unlock()
907 return nil, psrpc.NewErrorf(psrpc.NotFound, "dispatch ID not found")
908 }
909
910 delete(r.agentDispatches, dispatchID)
911 r.lock.Unlock()
912
913 // Should Delete be synchronous instead?
914 go func() {
915 ad.waitForPendingJobs()
916
917 var jobs []*livekit.Job
918 r.lock.RLock()
919 if ad.State != nil {
920 jobs = ad.State.Jobs
921 }
922 r.lock.RUnlock()
923
924 for _, j := range jobs {
925 state, err := r.agentClient.TerminateJob(context.Background(), j.Id, rpc.JobTerminateReason_TERMINATION_REQUESTED)
926 if err != nil {
927 continue
928 }
929 if state.ParticipantIdentity != "" {
930 r.lock.RLock()
931 agentJob := r.agentParticpants[livekit.ParticipantIdentity(state.ParticipantIdentity)]
932 p := r.participants[livekit.ParticipantIdentity(state.ParticipantIdentity)]
933 r.lock.RUnlock()
934
935 if p != nil {
936 if agentJob != nil {
937 err := agentJob.waitForParticipantLeaving()
938 if err == ErrJobShutdownTimeout {
939 r.logger.Infow("Agent Worker did not disconnect after 3s")
940 }
941 }
942 r.RemoveParticipant(p.Identity(), p.ID(), types.ParticipantCloseReasonServiceRequestRemoveParticipant)
943 }
944 }
945 r.lock.Lock()
946 j.State = state
947 r.lock.Unlock()
948 }
949 }()
950
951 return ad.AgentDispatch, nil
952}
953
954func (r *Room) OnRoomUpdated(f func()) {
955 r.onRoomUpdated = f

Callers

nothing calls this directly

Calls 6

RemoveParticipantMethod · 0.95
waitForPendingJobsMethod · 0.80
TerminateJobMethod · 0.65
IdentityMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected