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) {
dep.Log("End of Logs")
}
// waits for command execution and pipe reading
err = cmd.Wait()
// execute the script with timeout
done := make(chan error)
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
case err = <-done:
if err != nil {
return
}
}
if sink.Config.Debug.Scripts {
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