Skip to content

Commit

Permalink
fix: don't kill job immediately if timeout is not defined (#911)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrejs Golevs <a.golevs@dynatech.lv>
  • Loading branch information
andreygolev and Andrejs Golevs committed Mar 5, 2021
1 parent c874129 commit 92ac12b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions builtin/bins/dkron-executor-shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,21 @@ func (s *Shell) ExecuteImpl(args *dktypes.ExecuteRequest, cb dkplugin.StatusHelp
var jobTimeoutMessage string
var jobTimedOut bool

slowTimer := time.AfterFunc(jt, func() {
err = cmd.Process.Kill()
if err != nil {
jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. SIGKILL returned error. Job may not have been killed", command, jt)
} else {
jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. Job was killed", command, jt)
}

jobTimedOut = true
return
})

defer slowTimer.Stop()
if jt != 0 {
slowTimer := time.AfterFunc(jt, func() {
err = cmd.Process.Kill()
if err != nil {
jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. SIGKILL returned error. Job may not have been killed", command, jt)
} else {
jobTimeoutMessage = fmt.Sprintf("shell: Job '%s' execution time exceeding defined timeout %v. Job was killed", command, jt)
}

jobTimedOut = true
return
})

defer slowTimer.Stop()
}

// Warn if buffer is overwritten
if output.TotalWritten() > output.Size() {
Expand Down

0 comments on commit 92ac12b

Please sign in to comment.