Ability to disable auto-create (#361)
* setting to disable autocreate * improve test reliability * update comment * update to address feedback
This commit is contained in:
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/pkg/errors"
|
||||
@@ -11,6 +12,11 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
)
|
||||
|
||||
const (
|
||||
executionTimeout = 2 * time.Second
|
||||
checkInterval = 50 * time.Millisecond
|
||||
)
|
||||
|
||||
// A rooms service that supports a single node
|
||||
type RoomService struct {
|
||||
router routing.MessageRouter
|
||||
@@ -75,6 +81,21 @@ func (s *RoomService) DeleteRoom(ctx context.Context, req *livekit.DeleteRoomReq
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// we should not return until when the room is confirmed deleted
|
||||
err = confirmExecution(func() error {
|
||||
_, err := s.roomStore.LoadRoom(ctx, livekit.RoomName(req.Room))
|
||||
if err == nil {
|
||||
return ErrOperationFailed
|
||||
} else if err != ErrRoomNotFound {
|
||||
return err
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &livekit.DeleteRoomResponse{}, nil
|
||||
}
|
||||
|
||||
@@ -252,3 +273,20 @@ func (s *RoomService) writeRoomMessage(ctx context.Context, room livekit.RoomNam
|
||||
|
||||
return s.router.WriteRoomRTC(ctx, room, identity, msg)
|
||||
}
|
||||
|
||||
func confirmExecution(f func() error) error {
|
||||
expired := time.After(executionTimeout)
|
||||
var err error
|
||||
for {
|
||||
select {
|
||||
case <-expired:
|
||||
return err
|
||||
default:
|
||||
err = f()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
time.Sleep(checkInterval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user