Skip to content

Commit

Permalink
refactor(conf): improve kill_delay option
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmtrek committed Mar 21, 2020
1 parent 8efd558 commit ff8c2ed
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
8 changes: 4 additions & 4 deletions air_example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
include_dir = []
# Exclude files.
exclude_file = []
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop to run old binary when build errors occur.
# Stop running old binary when build errors occur.
stop_on_error = true
# This log file places in your tmp_dir.
log = "air_errors.log"
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 0
kill_delay = 500 # ms

[log]
# Show log time
Expand Down
6 changes: 1 addition & 5 deletions runner/util_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {
if err = syscall.Kill(-pid, syscall.SIGINT); err != nil {
return
}

time.Sleep(e.config.Build.KillDelay * time.Second)
time.Sleep(e.config.Build.KillDelay * time.Millisecond)
}

// https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly
err = syscall.Kill(-pid, syscall.SIGKILL)

// Wait releases any resources associated with the Process.
_, _ = cmd.Process.Wait()

return pid, err
}

Expand Down
4 changes: 1 addition & 3 deletions runner/util_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {
if err = syscall.Kill(-pid, syscall.SIGINT); err != nil {
return
}

time.Sleep(e.config.Build.KillDelay * time.Second)
time.Sleep(e.config.Build.KillDelay * time.Millisecond)
}

// https://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly
err = syscall.Kill(-pid, syscall.SIGKILL)

// Wait releases any resources associated with the Process.
_, _ = cmd.Process.Wait()

return
}

Expand Down
1 change: 0 additions & 1 deletion runner/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

func (e *Engine) killCmd(cmd *exec.Cmd) (pid int, err error) {
pid = cmd.Process.Pid

// https://stackoverflow.com/a/44551450
kill := exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(pid))
return pid, kill.Run()
Expand Down

0 comments on commit ff8c2ed

Please sign in to comment.