mirror of
https://github.com/hibiken/asynq.git
synced 2024-12-27 00:02:19 +08:00
Make Run method stateful
This commit is contained in:
parent
62db9863fb
commit
c6f482d4f8
8
asynq.go
8
asynq.go
@ -109,6 +109,9 @@ type Workers struct {
|
|||||||
// poolTokens is a counting semaphore to ensure the number of active workers
|
// poolTokens is a counting semaphore to ensure the number of active workers
|
||||||
// does not exceed the limit.
|
// does not exceed the limit.
|
||||||
poolTokens chan struct{}
|
poolTokens chan struct{}
|
||||||
|
|
||||||
|
// running indicates whether the workes are currently running.
|
||||||
|
running bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWorkers creates and returns a new Workers.
|
// NewWorkers creates and returns a new Workers.
|
||||||
@ -125,6 +128,11 @@ type TaskHandler func(*Task) error
|
|||||||
|
|
||||||
// Run starts the workers and scheduler with a given handler.
|
// Run starts the workers and scheduler with a given handler.
|
||||||
func (w *Workers) Run(handler TaskHandler) {
|
func (w *Workers) Run(handler TaskHandler) {
|
||||||
|
if w.running {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.running = true
|
||||||
|
|
||||||
go w.pollDeferred()
|
go w.pollDeferred()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user