Expose queue unprocessed and items being processed len

This commit is contained in:
Jose Fernandez
2023-09-15 15:22:44 -06:00
committed by Pires
parent 2ee2d9f63b
commit 238aebad73
2 changed files with 51 additions and 3 deletions

View File

@@ -288,6 +288,24 @@ func (q *Queue) Len() int {
return q.items.Len() + len(q.itemsBeingProcessed)
}
// UnprocessedLen returns the count of items yet to be processed in the queue
func (q *Queue) UnprocessedLen() int {
q.lock.Lock()
defer q.lock.Unlock()
if q.items.Len() != len(q.itemsInQueue) {
panic("Internally inconsistent state")
}
return len(q.itemsInQueue)
}
// ProcessedLen returns the count items that are being processed
func (q *Queue) ItemsBeingProcessedLen() int {
q.lock.Lock()
defer q.lock.Unlock()
return len(q.itemsBeingProcessed)
}
// Run starts the workers
//
// It blocks until context is cancelled, and all of the workers exit.