diff options
author | Wolfy-J <[email protected]> | 2019-05-02 18:21:36 +0300 |
---|---|---|
committer | Wolfy-J <[email protected]> | 2019-05-02 18:21:36 +0300 |
commit | eb8c64941cbcd30ff79b6147efd5fef42eccb648 (patch) | |
tree | bde0ceb7e7236850cfe999da7c3ffecf62b58d00 /worker.go | |
parent | 34abca68708ed881c3360ee749d794b0000a3aec (diff) |
miiiinor performance optimizations
Diffstat (limited to 'worker.go')
-rw-r--r-- | worker.go | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -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) |