diff options
Diffstat (limited to 'pkg/worker')
-rwxr-xr-x | pkg/worker/sync_worker.go | 9 | ||||
-rwxr-xr-x | pkg/worker/worker.go | 33 |
2 files changed, 14 insertions, 28 deletions
diff --git a/pkg/worker/sync_worker.go b/pkg/worker/sync_worker.go index eacb8a8a..11992f22 100755 --- a/pkg/worker/sync_worker.go +++ b/pkg/worker/sync_worker.go @@ -63,9 +63,10 @@ type wexec struct { } // Exec payload without TTL timeout. -func (tw *syncWorker) ExecWithContext(ctx context.Context, p payload.Payload) (payload.Payload, error) { - const op = errors.Op("ExecWithContext") +func (tw *syncWorker) ExecWithTimeout(ctx context.Context, p payload.Payload) (payload.Payload, error) { + const op = errors.Op("ExecWithTimeout") c := make(chan wexec, 1) + go func() { if len(p.Body) == 0 && len(p.Context) == 0 { c <- wexec{ @@ -211,8 +212,8 @@ func (tw *syncWorker) Wait() error { return tw.w.Wait() } -func (tw *syncWorker) Stop(ctx context.Context) error { - return tw.w.Stop(ctx) +func (tw *syncWorker) Stop() error { + return tw.w.Stop() } func (tw *syncWorker) Kill() error { diff --git a/pkg/worker/worker.go b/pkg/worker/worker.go index e60ab3f4..456f4bea 100755 --- a/pkg/worker/worker.go +++ b/pkg/worker/worker.go @@ -2,7 +2,6 @@ package worker import ( "bytes" - "context" "fmt" "io" "os" @@ -220,30 +219,16 @@ func (w *Process) closeRelay() error { } // Stop sends soft termination command to the Process and waits for process completion. -func (w *Process) Stop(ctx context.Context) error { - c := make(chan error) - - go func() { - var err error - w.state.Set(internal.StateStopping) - err = multierr.Append(err, internal.SendControl(w.relay, &internal.StopCommand{Stop: true})) - if err != nil { - w.state.Set(internal.StateKilling) - c <- multierr.Append(err, w.cmd.Process.Kill()) - } - w.state.Set(internal.StateStopped) - c <- nil - }() - - select { - case <-ctx.Done(): - return ctx.Err() - case err := <-c: - if err != nil { - return err - } - return nil +func (w *Process) Stop() error { + var err error + w.state.Set(internal.StateStopping) + err = multierr.Append(err, internal.SendControl(w.relay, &internal.StopCommand{Stop: true})) + if err != nil { + w.state.Set(internal.StateKilling) + return multierr.Append(err, w.cmd.Process.Kill()) } + w.state.Set(internal.StateStopped) + return nil } // Kill kills underlying process, make sure to call Wait() func to gather |