mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +08:00
Terminate background upon receiving SIGTERM or SIGINT
This commit is contained in:
parent
12fc336889
commit
911e600c41
@ -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...")
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user