Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type (
routineGroup *routineGroup
quit chan struct{}
ready chan struct{}
notify chan struct{}
worker core.Worker
stopOnce sync.Once
stopFlag int32
Expand All @@ -44,6 +45,7 @@ func NewQueue(opts ...Option) (*Queue, error) {
routineGroup: newRoutineGroup(),
quit: make(chan struct{}),
ready: make(chan struct{}, 1),
notify: make(chan struct{}, 1),
workerCount: o.workerCount,
logger: o.logger,
worker: o.worker,
Expand Down Expand Up @@ -149,6 +151,13 @@ func (q *Queue) queue(m *job.Message) error {
}

q.metric.IncSubmittedTask()
// notify worker
// if the channel is full, it means that the worker is busy
// and we don't want to block the main thread
select {
case q.notify <- struct{}{}:
default:
}

return nil
}
Expand Down Expand Up @@ -325,6 +334,7 @@ func (q *Queue) start() {
return
}
case <-ticker.C:
case <-q.notify:
}
}
}
Expand Down
Loading