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.
()
| 14 | // so the Task process is not killed immediately and processes running have |
| 15 | // time to do cleanup work. |
| 16 | func (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 | } |