Skip to content

Commit

Permalink
move all time.Sleep() to one place to identify properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Nov 24, 2023
1 parent 3551de5 commit 922910d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
13 changes: 9 additions & 4 deletions pkg/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package config
import "time"

const (
RECORDER_BOT = "RECORDER_BOT"
RTMP_BOT = "RTMP_BOT"
MAX_PRELOADED_WHITEBOARD_FILE_SIZE int64 = 5 * 1000000 // limit to 5MB
WAIT_BEFORE_TRIGGER_ON_AFTER_ROOM_ENDED = 5 * time.Second
RecorderBot = "RECORDER_BOT"
RtmpBot = "RTMP_BOT"
MaxPreloadedWhiteboardFileSize int64 = 5 * 1000000 // limit to 5MB

// all the time.Sleep() values
WaitBeforeTriggerOnAfterRoomEnded = 5 * time.Second
WaitBeforeSpeechServicesOnAfterRoomEnded = 3 * time.Second
WaitBeforeBreakoutRoomOnAfterRoomStart = 2 * time.Second
WaitBeforeAnalyticsStartProcessing = 30 * time.Second
)
7 changes: 3 additions & 4 deletions pkg/models/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import (
)

const (
analyticsRoomKey = "pnm:analytics:%s"
analyticsUserKey = analyticsRoomKey + ":user:%s"
waitBeforeProcessDuration = time.Second * 30
analyticsRoomKey = "pnm:analytics:%s"
analyticsUserKey = analyticsRoomKey + ":user:%s"
)

type AnalyticsModel struct {
Expand Down Expand Up @@ -162,7 +161,7 @@ func (m *AnalyticsModel) PrepareToExportAnalytics(roomId, sid, meta string) {
}

// let's wait a few seconds so that all other processes will finish
time.Sleep(waitBeforeProcessDuration)
time.Sleep(config.WaitBeforeAnalyticsStartProcessing)

// we'll check if the room is still active or not.
// this may happen when we closed the room & re-created it instantly
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/breakout_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (m *BreakoutRoom) EndBreakoutRooms(roomId string) error {
func (m *BreakoutRoom) PostTaskAfterRoomStartWebhook(roomId string, metadata *plugnmeet.RoomMetadata) error {
// now in livekit rooms are created almost instantly & sending webhook response
// if this happened then we'll have to wait few seconds otherwise room info can't be found
time.Sleep(2 * time.Second)
time.Sleep(config.WaitBeforeBreakoutRoomOnAfterRoomStart)

room, err := m.fetchBreakoutRoom(metadata.ParentRoomId, roomId)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func (r *RecorderModel) SendMsgToRecorder(req *plugnmeet.RecordingReq) error {

switch req.Task {
case plugnmeet.RecordingTasks_START_RECORDING:
err := r.addTokenAndRecorder(toSend, config.RECORDER_BOT)
err := r.addTokenAndRecorder(toSend, config.RecorderBot)
if err != nil {
return err
}
case plugnmeet.RecordingTasks_START_RTMP:
toSend.RtmpUrl = req.RtmpUrl
err := r.addTokenAndRecorder(toSend, config.RTMP_BOT)
err := r.addTokenAndRecorder(toSend, config.RtmpBot)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/models/room_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func NewRoomAuthModel() *RoomAuthModel {
func (am *RoomAuthModel) CreateRoom(r *plugnmeet.CreateRoomReq) (bool, string, *livekit.Room) {
exist, err := am.rs.ManageActiveRoomsWithMetadata(r.GetRoomId(), "get", "")
if err == nil && exist != nil {
waitFor := config.WAIT_BEFORE_TRIGGER_ON_AFTER_ROOM_ENDED + (1 * time.Second)
// maybe this room was ended just now, so we'll wait until clean up done
waitFor := config.WaitBeforeTriggerOnAfterRoomEnded + (1 * time.Second)
log.Infoln("this room:", r.GetRoomId(), "still active, we'll wait for:", waitFor, "before recreating it again.")
time.Sleep(waitFor)
}
Expand Down Expand Up @@ -366,8 +366,8 @@ func (am *RoomAuthModel) prepareWhiteboardPreloadFile(req *plugnmeet.CreateRoomR
if resp.ContentLength < 1 {
log.Errorf("invalid file type")
return
} else if resp.ContentLength > config.MAX_PRELOADED_WHITEBOARD_FILE_SIZE {
log.Errorf("Allowd %d but given %d", config.MAX_PRELOADED_WHITEBOARD_FILE_SIZE, resp.ContentLength)
} else if resp.ContentLength > config.MaxPreloadedWhiteboardFileSize {
log.Errorf("Allowd %d but given %d", config.MaxPreloadedWhiteboardFileSize, resp.ContentLength)
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *SchedulerModel) activeRoomChecker() {
}
var count int64 = 0
for _, p := range pp {
if p.Identity == config.RECORDER_BOT || p.Identity == config.RTMP_BOT {
if p.Identity == config.RecorderBot || p.Identity == config.RtmpBot {
continue
}
count++
Expand Down
4 changes: 2 additions & 2 deletions pkg/models/speech_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ func (s *SpeechServices) OnAfterRoomEnded(roomId, sId string) {
if sId == "" {
return
}
// we'll wait little bit to make sure all users' requested has been received
time.Sleep(5 * time.Microsecond)
// we'll wait a little bit to make sure all users' requested has been received
time.Sleep(config.WaitBeforeSpeechServicesOnAfterRoomEnded)

key := fmt.Sprintf("%s:%s:usage", SpeechServiceRedisKey, roomId)
hkeys, err := s.rc.HKeys(s.ctx, key).Result()
Expand Down
2 changes: 1 addition & 1 deletion pkg/models/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (w *webhookEvent) roomFinished() {
// now we'll perform a few service related tasks
go func() {
// let's wait a few seconds so that any pending task will finish
time.Sleep(config.WAIT_BEFORE_TRIGGER_ON_AFTER_ROOM_ENDED)
time.Sleep(config.WaitBeforeTriggerOnAfterRoomEnded)
w.roomService.OnAfterRoomClosed(event.Room.Name)
}()

Expand Down

0 comments on commit 922910d

Please sign in to comment.