snapshot of https://github.com/ThreeDotsLabs/watermill.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
master / ci (push) Failing after 0s
Some checks failed
master / ci (push) Failing after 0s
This commit is contained in:
27
message/router/plugin/signals.go
Normal file
27
message/router/plugin/signals.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/ThreeDotsLabs/watermill/message"
|
||||
)
|
||||
|
||||
// SignalsHandler is a plugin that kills the router after SIGINT or SIGTERM is sent to the process.
|
||||
func SignalsHandler(r *message.Router) error {
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
|
||||
go func() {
|
||||
sig := <-sigs
|
||||
r.Logger().Info(fmt.Sprintf("Received %s signal, closing\n", sig), nil)
|
||||
|
||||
err := r.Close()
|
||||
if err != nil {
|
||||
r.Logger().Error("Router close failed", err, nil)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user