summaryrefslogtreecommitdiff
path: root/worker.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-06-05 22:48:27 +0300
committerWolfy-J <[email protected]>2018-06-05 22:48:27 +0300
commit6adaf713b47c9a3ab3a516e21d2d4ecf7f2075d6 (patch)
tree6bcf1bfea1e2f87a3ae7065612c0df43c90c1cdc /worker.go
parent3112f9b58c73773cea972fd79f04d33f8f7d7edd (diff)
breaking the tests
Diffstat (limited to 'worker.go')
-rw-r--r--worker.go25
1 files changed, 20 insertions, 5 deletions
diff --git a/worker.go b/worker.go
index 6bd317d8..ab0af052 100644
--- a/worker.go
+++ b/worker.go
@@ -110,9 +110,16 @@ func (w *Worker) Wait() error {
}
if w.endState.Success() {
+ w.state.set(StateStopped)
return nil
}
+ if w.state.Value() != StateDestructing {
+ w.state.set(StateErrored)
+ } else {
+ w.state.set(StateStopped)
+ }
+
if w.err.Len() != 0 {
return errors.New(w.err.String())
}
@@ -123,6 +130,17 @@ func (w *Worker) Wait() error {
// Stop sends soft termination command to the worker and waits for process completion.
func (w *Worker) Stop() error {
+ return w.doStop(StateStopping)
+}
+
+// Destroy is identical to stop command but does mark workers with different state. Destroyed workers won't
+// throw error state on completion of process destruction (exit status).
+func (w *Worker) Destroy() error {
+ return w.doStop(StateDestructing)
+}
+
+// actual stopping.
+func (w *Worker) doStop(state int64) error {
select {
case <-w.waitDone:
return nil
@@ -130,7 +148,7 @@ func (w *Worker) Stop() error {
w.mu.Lock()
defer w.mu.Unlock()
- w.state.set(StateInactive)
+ w.state.set(state)
err := sendPayload(w.rl, &stopCommand{Stop: true})
<-w.waitDone
@@ -145,7 +163,7 @@ func (w *Worker) Kill() error {
case <-w.waitDone:
return nil
default:
- w.state.set(StateInactive)
+ w.state.set(StateDestructing)
err := w.cmd.Process.Signal(os.Kill)
<-w.waitDone
@@ -172,7 +190,6 @@ func (w *Worker) Exec(rqs *Payload) (rsp *Payload, err error) {
defer w.state.registerExec()
rsp, err = w.execPayload(rqs)
-
if err != nil {
if _, ok := err.(JobError); !ok {
w.state.set(StateErrored)
@@ -196,9 +213,7 @@ func (w *Worker) start() error {
go func() {
w.endState, _ = w.cmd.Process.Wait()
if w.waitDone != nil {
- w.state.set(StateStopped)
close(w.waitDone)
-
if w.rl != nil {
w.mu.Lock()
defer w.mu.Unlock()