2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 11:31:58 +08:00

Update log messages on shutdown

This commit is contained in:
Ken Hibino 2019-11-27 06:33:04 -08:00
parent 60132f3208
commit e6b1230c36
3 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,7 @@
package asynq package asynq
import ( import (
"fmt"
"os" "os"
"os/signal" "os/signal"
"sync" "sync"
@ -49,6 +50,7 @@ func (bg *Background) Run(handler TaskHandler) {
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, os.Kill) signal.Notify(sigs, os.Interrupt, os.Kill)
<-sigs <-sigs
fmt.Printf("\nStarting graceful shutdown...\n")
} }
// starts the background-task processing. // starts the background-task processing.

View File

@ -29,6 +29,7 @@ func newPoller(rdb *rdb, avgInterval time.Duration, zsets []string) *poller {
} }
func (p *poller) terminate() { func (p *poller) terminate() {
fmt.Print("Poller shutting down...")
// Signal the poller goroutine to stop polling. // Signal the poller goroutine to stop polling.
p.done <- struct{}{} p.done <- struct{}{}
} }
@ -39,9 +40,7 @@ func (p *poller) start() {
for { for {
select { select {
case <-p.done: case <-p.done:
fmt.Println("-------------[Poller]---------------") fmt.Println("Done")
fmt.Println("Poller shutting down...")
fmt.Println("------------------------------------")
return return
default: default:
p.exec() p.exec()

View File

@ -29,15 +29,16 @@ func newProcessor(rdb *rdb, numWorkers int, handler TaskHandler) *processor {
} }
func (p *processor) terminate() { func (p *processor) terminate() {
fmt.Print("Processor shutting down...")
// Signal the processor goroutine to stop processing tasks from the queue. // Signal the processor goroutine to stop processing tasks from the queue.
p.done <- struct{}{} p.done <- struct{}{}
fmt.Println("--- Waiting for all workers to finish ---") fmt.Print("Waiting for all workers to finish...")
for i := 0; i < cap(p.sema); i++ { for i := 0; i < cap(p.sema); i++ {
// block until all workers have released the token // block until all workers have released the token
p.sema <- struct{}{} p.sema <- struct{}{}
} }
fmt.Println("--- All workers have finished! ----") fmt.Println("Done")
} }
func (p *processor) start() { func (p *processor) start() {
@ -48,9 +49,7 @@ func (p *processor) start() {
for { for {
select { select {
case <-p.done: case <-p.done:
fmt.Println("-------------[Processor]---------------") fmt.Println("Done")
fmt.Println("Processor shutting down...")
fmt.Println("-------------------------------------")
return return
default: default:
p.exec() p.exec()