Warn on ops queue full (#481)

Pass logger so that we can log with proper context.
This commit is contained in:
Raja Subramanian
2022-03-02 19:08:07 +05:30
committed by GitHub
parent bfa350451e
commit c743d2ab3a
7 changed files with 38 additions and 16 deletions
+16 -3
View File
@@ -2,6 +2,8 @@ package utils
import (
"sync"
"github.com/livekit/protocol/logger"
)
const (
@@ -9,17 +11,24 @@ const (
)
type OpsQueue struct {
logger logger.Logger
lock sync.RWMutex
ops chan func()
isStopped bool
}
func NewOpsQueue() *OpsQueue {
func NewOpsQueue(logger logger.Logger) *OpsQueue {
return &OpsQueue{
ops: make(chan func(), MaxOps),
logger: logger,
ops: make(chan func(), MaxOps),
}
}
func (oq *OpsQueue) SetLogger(logger logger.Logger) {
oq.logger = logger
}
func (oq *OpsQueue) Start() {
go oq.process()
}
@@ -43,7 +52,11 @@ func (oq *OpsQueue) Enqueue(op func()) {
return
}
oq.ops <- op
select {
case oq.ops <- op:
default:
oq.logger.Warnw("ops queue full", nil)
}
oq.lock.RUnlock()
}