Skip to content

Commit

Permalink
use same loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Jul 18, 2022
1 parent 194cfaf commit 72ccb10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/server/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const Version = "1.1.5"
const Version = "1.1.6"
30 changes: 9 additions & 21 deletions internal/models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type scheduler struct {
rc *redis.Client
ctx context.Context
ra *roomAuthModel
ticker *time.Ticker
closeTicker chan bool
}

Expand All @@ -27,18 +26,22 @@ func NewSchedulerModel() *scheduler {

func (s *scheduler) StartScheduler() {
go s.subscribeRedisRoomDurationChecker()
go s.startActiveRoomChecker()

s.ticker = time.NewTicker(5 * time.Second)
defer s.ticker.Stop()
s.closeTicker = make(chan bool)
checkRoomDuration := time.NewTicker(5 * time.Second)
defer checkRoomDuration.Stop()

roomChecker := time.NewTicker(5 * time.Minute)
defer roomChecker.Stop()

for {
select {
case <-s.closeTicker:
return
case <-s.ticker.C:
case <-checkRoomDuration.C:
s.checkRoomWithDuration()
case <-roomChecker.C:
s.activeRoomChecker()
}
}
}
Expand Down Expand Up @@ -111,22 +114,7 @@ func (s *scheduler) increaseRoomDuration(roomId string, duration int64) {
}
}

// startActiveRoomChecker will check & do reconciliation between DB & livekit
func (s *scheduler) startActiveRoomChecker() {
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()
closeTicker := make(chan bool)

for {
select {
case <-closeTicker:
return
case <-ticker.C:
s.activeRoomChecker()
}
}
}

// activeRoomChecker will check & do reconciliation between DB & livekit
func (s *scheduler) activeRoomChecker() {
status, _, activeRooms := s.ra.GetActiveRoomsInfo()
if !status {
Expand Down

0 comments on commit 72ccb10

Please sign in to comment.