1
0
mirror of https://github.com/go-task/task.git synced 2025-11-23 22:24:45 +02:00

Update minimum go version (#1758)

* feat: update minimum version to 1.22

* refactor: use int range iterator

* refactor: loop variables

* refactor: replace slicesext.FirstNonZero with cmp.Or

* refactor: use slices.Concat instead of append

* fix: unused param

* fix: linting
This commit is contained in:
Pete Davison
2024-08-14 14:37:05 +01:00
committed by GitHub
parent 51c569ef37
commit 5e9851f42f
18 changed files with 50 additions and 60 deletions

View File

@@ -8,24 +8,25 @@ import (
"github.com/go-task/task/v3/internal/logger"
)
const interruptSignalsCount = 3
// 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.
func (e *Executor) InterceptInterruptSignals() {
ch := make(chan os.Signal, 3)
ch := make(chan os.Signal, interruptSignalsCount)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
go func() {
for i := 1; i <= 3; i++ {
for i := range interruptSignalsCount {
sig := <-ch
if i < 3 {
e.Logger.Outf(logger.Yellow, "task: Signal received: %q\n", sig)
continue
if i+1 >= interruptSignalsCount {
e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
os.Exit(1)
}
e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
os.Exit(1)
e.Logger.Outf(logger.Yellow, "task: Signal received: %q\n", sig)
}
}()
}