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:
parent
60132f3208
commit
e6b1230c36
@ -1,6 +1,7 @@
|
||||
package asynq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
@ -49,6 +50,7 @@ func (bg *Background) Run(handler TaskHandler) {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, os.Interrupt, os.Kill)
|
||||
<-sigs
|
||||
fmt.Printf("\nStarting graceful shutdown...\n")
|
||||
}
|
||||
|
||||
// starts the background-task processing.
|
||||
|
@ -29,6 +29,7 @@ func newPoller(rdb *rdb, avgInterval time.Duration, zsets []string) *poller {
|
||||
}
|
||||
|
||||
func (p *poller) terminate() {
|
||||
fmt.Print("Poller shutting down...")
|
||||
// Signal the poller goroutine to stop polling.
|
||||
p.done <- struct{}{}
|
||||
}
|
||||
@ -39,9 +40,7 @@ func (p *poller) start() {
|
||||
for {
|
||||
select {
|
||||
case <-p.done:
|
||||
fmt.Println("-------------[Poller]---------------")
|
||||
fmt.Println("Poller shutting down...")
|
||||
fmt.Println("------------------------------------")
|
||||
fmt.Println("Done")
|
||||
return
|
||||
default:
|
||||
p.exec()
|
||||
|
@ -29,15 +29,16 @@ func newProcessor(rdb *rdb, numWorkers int, handler TaskHandler) *processor {
|
||||
}
|
||||
|
||||
func (p *processor) terminate() {
|
||||
fmt.Print("Processor shutting down...")
|
||||
// Signal the processor goroutine to stop processing tasks from the queue.
|
||||
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++ {
|
||||
// block until all workers have released the token
|
||||
p.sema <- struct{}{}
|
||||
}
|
||||
fmt.Println("--- All workers have finished! ----")
|
||||
fmt.Println("Done")
|
||||
}
|
||||
|
||||
func (p *processor) start() {
|
||||
@ -48,9 +49,7 @@ func (p *processor) start() {
|
||||
for {
|
||||
select {
|
||||
case <-p.done:
|
||||
fmt.Println("-------------[Processor]---------------")
|
||||
fmt.Println("Processor shutting down...")
|
||||
fmt.Println("-------------------------------------")
|
||||
fmt.Println("Done")
|
||||
return
|
||||
default:
|
||||
p.exec()
|
||||
|
Loading…
Reference in New Issue
Block a user