2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-26 07:42:17 +08:00

Terminate background upon receiving SIGTERM or SIGINT

This commit is contained in:
Ken Hibino 2019-12-16 20:19:05 -08:00
parent 12fc336889
commit 911e600c41
2 changed files with 4 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"os/signal" "os/signal"
"sync" "sync"
"syscall"
"time" "time"
"github.com/hibiken/asynq/internal/rdb" "github.com/hibiken/asynq/internal/rdb"
@ -74,9 +75,9 @@ func (bg *Background) Run(handler Handler) {
bg.start(handler) bg.start(handler)
defer bg.stop() defer bg.stop()
// Wait for a signal to exit. // Wait for a signal to terminate.
sigs := make(chan os.Signal, 1) sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, os.Kill) signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT)
<-sigs <-sigs
fmt.Println() fmt.Println()
log.Println("[INFO] Starting graceful shutdown...") log.Println("[INFO] Starting graceful shutdown...")