Commit 501743d0 authored by lukasburgey's avatar lukasburgey
Browse files

Add timeout to the script execution

Closes #12
parent 32658058
...@@ -136,11 +136,24 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) { ...@@ -136,11 +136,24 @@ func (sink *Sink) handleDep(dep deps.Dep) (output scripts.Output, err error) {
dep.Log("End of Logs") dep.Log("End of Logs")
} }
// waits for command execution and pipe reading // execute the script with timeout
err = cmd.Wait() done := make(chan error)
if err != nil { go func() { done <- cmd.Wait() }()
// TODO put in config
timeoutDuration := 2 * time.Second
timeout := time.After(timeoutDuration)
select {
case <-timeout:
cmd.Process.Kill()
err = fmt.Errorf("Execution of '%s' timed out after %s", dep.Service.Command, timeoutDuration)
return return
case err = <-done:
if err != nil {
return
}
} }
if sink.Config.Debug.Scripts { if sink.Config.Debug.Scripts {
dep.Log("Output: %s", indent.Indent(stdoutBytes)) dep.Log("Output: %s", indent.Indent(stdoutBytes))
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment