Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notify mechanism fix for new task added #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 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{}
newTaskAdded chan struct{}
worker core.Worker
stopOnce sync.Once
stopFlag int32
Expand All @@ -43,6 +44,7 @@ func NewQueue(opts ...Option) (*Queue, error) {
routineGroup: newRoutineGroup(),
quit: make(chan struct{}),
ready: make(chan struct{}, 1),
newTaskAdded: make(chan struct{}),
workerCount: o.workerCount,
logger: o.logger,
worker: o.worker,
Expand Down Expand Up @@ -147,6 +149,7 @@ func (q *Queue) queue(m *job.Message) error {
}

q.metric.IncSubmittedTask()
q.newTaskAdded <- struct{}{}

return nil
}
Expand Down Expand Up @@ -320,8 +323,8 @@ func (q *Queue) start() {
close(tasks)
return
}
case <-time.After(time.Second):
// sleep 1 second to fetch new task
case <-q.newTaskAdded:
// New task added
}
}
}
Expand Down
Loading