Skip to content

Commit

Permalink
refactor: signal handling to improve clarity and correctness (#1980)
Browse files Browse the repository at this point in the history
  • Loading branch information
EinoPlasma authored Jan 18, 2025
1 parent bad2c8f commit 65a71e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import (
"github.com/go-task/task/v3/internal/logger"
)

const interruptSignalsCount = 3
const maxInterruptSignals = 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, interruptSignalsCount)
ch := make(chan os.Signal, maxInterruptSignals)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)

go func() {
for i := range interruptSignalsCount {
for i := 0; i < maxInterruptSignals; i++ {
sig := <-ch

if i+1 >= interruptSignalsCount {
if i+1 >= maxInterruptSignals {
e.Logger.Errf(logger.Red, "task: Signal received for the third time: %q. Forcing shutdown\n", sig)
os.Exit(1)
}
Expand Down

0 comments on commit 65a71e5

Please sign in to comment.