2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-24 10:36:12 +08:00
Allow a server instance to be gracefully shutdown programmatically
This commit is contained in:
herb
2022-04-22 13:38:46 -07:00
parent 5c723f597e
commit d1e5e4f2f1
4 changed files with 34 additions and 11 deletions

View File

@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package asynq
@@ -16,14 +17,22 @@ import (
// Note: Currently SIGTSTP is not supported for windows build.
func (srv *Server) waitForSignals() {
srv.logger.Info("Send signal TERM or INT to terminate the process")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, windows.SIGTERM, windows.SIGINT)
<-sigs
signal.Notify(srv.sigs, os.Interrupt, windows.SIGTERM, windows.SIGINT)
<-srv.sigs
}
// SignalShutdown stops and shuts down the server.
func (srv *Server) SignalShutdown() {
srv.sigs <- os.Interrupt
}
func (s *Scheduler) waitForSignals() {
s.logger.Info("Send signal TERM or INT to stop the scheduler")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, windows.SIGTERM, windows.SIGINT)
<-sigs
signal.Notify(s.sigs, os.Interrupt, windows.SIGTERM, windows.SIGINT)
<-s.sigs
}
// SignalShutdown stops and shuts down the scheduler.
func (s *Scheduler) SignalShutdown() {
s.sigs <- os.Interrupt
}