From 7ecf55b3f608ffe27020fbbd9a8299d7cf28db24 Mon Sep 17 00:00:00 2001 From: Max Claus Nunes Date: Sun, 18 Nov 2018 12:41:08 -0200 Subject: [PATCH] Fix issue of gaper not restarting after a previous failure Close #8 --- gaper.go | 3 ++- runner.go | 6 ++++++ testdata/mocks.go | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gaper.go b/gaper.go index 619e0dc..fe4e420 100644 --- a/gaper.go +++ b/gaper.go @@ -103,7 +103,8 @@ func run(cfg *Config, chOSSiginal chan os.Signal, builder Builder, runner Runner continue } - changeRestart = true + changeRestart = runner.IsRunning() + if err := restart(builder, runner); err != nil { return err } diff --git a/runner.go b/runner.go index bee7f90..8bb5af9 100644 --- a/runner.go +++ b/runner.go @@ -23,6 +23,7 @@ type Runner interface { Kill() error Errors() chan error Exited() bool + IsRunning() bool ExitStatus(err error) int } @@ -108,6 +109,11 @@ func (r *runner) Exited() bool { return r.command != nil && r.command.ProcessState != nil && r.command.ProcessState.Exited() } +// IsRunning returns if the process is running +func (r *runner) IsRunning() bool { + return r.command != nil && r.command.Process != nil && r.command.Process.Pid > 0 +} + // Errors get errors occurred during the build func (r *runner) Errors() chan error { return r.errors diff --git a/testdata/mocks.go b/testdata/mocks.go index 11af253..36ddfb0 100644 --- a/testdata/mocks.go +++ b/testdata/mocks.go @@ -57,6 +57,12 @@ func (m *MockRunner) Exited() bool { return args.Bool(0) } +// IsRunning ... +func (m *MockRunner) IsRunning() bool { + args := m.Called() + return args.Bool(0) +} + // ExitStatus ... func (m *MockRunner) ExitStatus(err error) int { args := m.Called()