summaryrefslogtreecommitdiff
path: root/worker.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-05-02 18:21:36 +0300
committerWolfy-J <[email protected]>2019-05-02 18:21:36 +0300
commiteb8c64941cbcd30ff79b6147efd5fef42eccb648 (patch)
treebde0ceb7e7236850cfe999da7c3ffecf62b58d00 /worker.go
parent34abca68708ed881c3360ee749d794b0000a3aec (diff)
miiiinor performance optimizations
Diffstat (limited to 'worker.go')
-rw-r--r--worker.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/worker.go b/worker.go
index 04b58e49..7221c2de 100644
--- a/worker.go
+++ b/worker.go
@@ -164,38 +164,35 @@ func (w *Worker) Kill() error {
// errors. Method might return JobError indicating issue with payload.
func (w *Worker) Exec(rqs *Payload) (rsp *Payload, err error) {
w.mu.Lock()
- defer w.mu.Unlock()
if rqs == nil {
+ w.mu.Unlock()
return nil, fmt.Errorf("payload can not be empty")
}
if w.state.Value() != StateReady {
+ w.mu.Unlock()
return nil, fmt.Errorf("worker is not ready (%s)", w.state.String())
}
w.state.set(StateWorking)
- defer w.state.registerExec()
rsp, err = w.execPayload(rqs)
if err != nil {
if _, ok := err.(JobError); !ok {
w.state.set(StateErrored)
+ w.state.registerExec()
+ w.mu.Unlock()
return nil, err
}
}
- // todo: attach when payload is complete
- // todo: new status
-
w.state.set(StateReady)
+ w.state.registerExec()
+ w.mu.Unlock()
return rsp, err
}
-func (w *Worker) markDestroying() {
- w.state.set(StateDestroying)
-}
-
func (w *Worker) start() error {
if err := w.cmd.Start(); err != nil {
close(w.waitDone)