From 911e600c41b8318c690f887ec29c9fd5ed5a5d32 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Mon, 16 Dec 2019 20:19:05 -0800 Subject: [PATCH] Terminate background upon receiving SIGTERM or SIGINT --- background.go | 5 +++-- internal/rdb/rdb.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/background.go b/background.go index 42731fa..8cc03ea 100644 --- a/background.go +++ b/background.go @@ -6,6 +6,7 @@ import ( "os" "os/signal" "sync" + "syscall" "time" "github.com/hibiken/asynq/internal/rdb" @@ -74,9 +75,9 @@ func (bg *Background) Run(handler Handler) { bg.start(handler) defer bg.stop() - // Wait for a signal to exit. + // Wait for a signal to terminate. sigs := make(chan os.Signal, 1) - signal.Notify(sigs, os.Interrupt, os.Kill) + signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT) <-sigs fmt.Println() log.Println("[INFO] Starting graceful shutdown...") diff --git a/internal/rdb/rdb.go b/internal/rdb/rdb.go index 859e0b7..c8f9e5f 100644 --- a/internal/rdb/rdb.go +++ b/internal/rdb/rdb.go @@ -144,7 +144,7 @@ func (r *RDB) Retry(msg *TaskMessage, processAt time.Time, errMsg string) error if err != nil { return fmt.Errorf("could not marshal %+v to json: %v", modified, err) } - // KEYS[1] -> asynq:in_progress + // KEYS[1] -> asynq:in_progress // KEYS[2] -> asynq:retry // ARGV[1] -> TaskMessage value to remove from InProgress queue // ARGV[2] -> TaskMessage value to add to Retry queue