Ingress psrpc (#1295)
* add ingress psrpc codegen * use psrpc for ingress * merge entity/info update psrpc services * split update/delete ingress methods * add race helper test * add race context cancel test * sync race result with mutex
This commit is contained in:
+28
-60
@@ -258,19 +258,23 @@ func (s *EgressService) UpdateStream(ctx context.Context, req *livekit.UpdateStr
|
||||
return nil, ErrEgressNotConnected
|
||||
}
|
||||
|
||||
f0 := func() (*livekit.EgressInfo, error) {
|
||||
return s.clientDeprecated.SendRequest(ctx, &livekit.EgressRequest{
|
||||
EgressId: req.EgressId,
|
||||
Request: &livekit.EgressRequest_UpdateStream{
|
||||
UpdateStream: req,
|
||||
},
|
||||
race := rpc.NewRace[livekit.EgressInfo](ctx)
|
||||
if s.clientDeprecated != nil {
|
||||
race.Go(func(ctx context.Context) (*livekit.EgressInfo, error) {
|
||||
return s.clientDeprecated.SendRequest(ctx, &livekit.EgressRequest{
|
||||
EgressId: req.EgressId,
|
||||
Request: &livekit.EgressRequest_UpdateStream{
|
||||
UpdateStream: req,
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
f1 := func() (*livekit.EgressInfo, error) {
|
||||
return s.psrpcClient.UpdateStream(ctx, req.EgressId, req)
|
||||
if s.psrpcClient != nil {
|
||||
race.Go(func(ctx context.Context) (*livekit.EgressInfo, error) {
|
||||
return s.psrpcClient.UpdateStream(ctx, req.EgressId, req)
|
||||
})
|
||||
}
|
||||
|
||||
info, err := s.getFirst(f0, f1)
|
||||
_, info, err := race.Wait()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -323,19 +327,23 @@ func (s *EgressService) StopEgress(ctx context.Context, req *livekit.StopEgressR
|
||||
}
|
||||
}
|
||||
|
||||
f0 := func() (*livekit.EgressInfo, error) {
|
||||
return s.clientDeprecated.SendRequest(ctx, &livekit.EgressRequest{
|
||||
EgressId: req.EgressId,
|
||||
Request: &livekit.EgressRequest_Stop{
|
||||
Stop: req,
|
||||
},
|
||||
race := rpc.NewRace[livekit.EgressInfo](ctx)
|
||||
if s.clientDeprecated != nil {
|
||||
race.Go(func(ctx context.Context) (*livekit.EgressInfo, error) {
|
||||
return s.clientDeprecated.SendRequest(ctx, &livekit.EgressRequest{
|
||||
EgressId: req.EgressId,
|
||||
Request: &livekit.EgressRequest_Stop{
|
||||
Stop: req,
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
f1 := func() (*livekit.EgressInfo, error) {
|
||||
return s.psrpcClient.StopEgress(ctx, req.EgressId, req)
|
||||
if s.psrpcClient != nil {
|
||||
race.Go(func(ctx context.Context) (*livekit.EgressInfo, error) {
|
||||
return s.psrpcClient.StopEgress(ctx, req.EgressId, req)
|
||||
})
|
||||
}
|
||||
|
||||
info, err = s.getFirst(f0, f1)
|
||||
_, info, err = race.Wait()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -436,43 +444,3 @@ func (s *EgressService) handleUpdate(info *livekit.EgressInfo) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove in future version
|
||||
func (s *EgressService) getFirst(f0, f1 func() (*livekit.EgressInfo, error)) (*livekit.EgressInfo, error) {
|
||||
if s.clientDeprecated == nil {
|
||||
return f1()
|
||||
}
|
||||
if s.psrpcClient == nil {
|
||||
return f0()
|
||||
}
|
||||
|
||||
type res struct {
|
||||
info *livekit.EgressInfo
|
||||
err error
|
||||
}
|
||||
v0 := make(chan *res, 1)
|
||||
v1 := make(chan *res, 1)
|
||||
|
||||
go func() {
|
||||
info, err := f0()
|
||||
v0 <- &res{
|
||||
info: info,
|
||||
err: err,
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
info, err := f1()
|
||||
v1 <- &res{
|
||||
info: info,
|
||||
err: err,
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case r := <-v0:
|
||||
return r.info, r.err
|
||||
case r := <-v1:
|
||||
return r.info, r.err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user