2
0
mirror of https://github.com/hibiken/asynq.git synced 2026-04-22 14:05:52 +08:00

Gracefully shutdown all scheduled goroutines on (*Launcher).Stop

This commit is contained in:
Ken Hibino
2019-11-19 07:38:09 -08:00
parent 195fd893be
commit e238d3835d
2 changed files with 21 additions and 16 deletions

View File

@@ -13,6 +13,7 @@ import (
type poller struct {
rdb *redis.Client
// channel to communicate back to the long running "poller" goroutine.
done chan struct{}
// poll interval on average
@@ -23,6 +24,8 @@ type poller struct {
}
func (p *poller) terminate() {
// send a signal to the manager goroutine to stop
// processing tasks from the queue.
p.done <- struct{}{}
}
@@ -31,7 +34,10 @@ func (p *poller) start() {
for {
select {
case <-p.done:
p.shutdown()
fmt.Println("-------------[Poller]---------------")
fmt.Println("Poller shutting down...")
fmt.Println("------------------------------------")
return
default:
p.enqueue()
time.Sleep(p.avgInterval)
@@ -80,10 +86,3 @@ func (p *poller) enqueue() {
}
}
}
func (p *poller) shutdown() {
// TODO(hibiken): implement this. Gracefully shutdown all active goroutines.
fmt.Println("-------------[Poller]---------------")
fmt.Println("Poller shutting down...")
fmt.Println("------------------------------------")
}