MCPcopy
hub / github.com/go-task/task / InterceptInterruptSignals

Method InterceptInterruptSignals

signals.go:16–32  ·  view source on GitHub ↗

NOTE(@andreynering): This function intercepts SIGINT and SIGTERM signals so the Task process is not killed immediately and processes running have time to do cleanup work.

()

Source from the content-addressed store, hash-verified

14// so the Task process is not killed immediately and processes running have
15// time to do cleanup work.
16func (e *Executor) InterceptInterruptSignals() {
17 ch := make(chan os.Signal, maxInterruptSignals)
18 signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
19
20 go func() {
21 for i := range maxInterruptSignals {
22 sig := <-ch
23
24 if i+1 >= maxInterruptSignals {
25 e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
26 os.Exit(1)
27 }
28
29 e.Logger.Outf(logger.Yellow, "task: Signal received: %q\n", sig)
30 }
31 }()
32}

Callers 1

runFunction · 0.95

Calls 2

ErrfMethod · 0.80
OutfMethod · 0.80

Tested by

no test coverage detected