summaryrefslogtreecommitdiff
path: root/worker.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-01-28 15:53:39 +0300
committerWolfy-J <[email protected]>2018-01-28 15:53:39 +0300
commita78f4a23ac2ee8be95b8dec6911e8d219b39dc34 (patch)
tree77f62f1df31da3622e0947925cbf3e368f1517a3 /worker.go
parent839069b8137878d2d229b8425ab06027539983a8 (diff)
stop by worker
Diffstat (limited to 'worker.go')
-rw-r--r--worker.go59
1 files changed, 27 insertions, 32 deletions
diff --git a/worker.go b/worker.go
index 6520ebfe..3cc4517e 100644
--- a/worker.go
+++ b/worker.go
@@ -87,38 +87,6 @@ func (w *Worker) String() string {
)
}
-// Start underlying process or return error
-func (w *Worker) Start() error {
- if w.cmd.Process != nil {
- return fmt.Errorf("process already running")
- }
-
- if err := w.cmd.Start(); err != nil {
- close(w.waitDone)
-
- return err
- }
-
- w.Pid = &w.cmd.Process.Pid
-
- // wait for process to complete
- 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()
- w.rl.Close()
- }
- }
- }()
-
- return nil
-}
-
// Wait must be called once for each worker, call will be released once worker is
// complete and will return process error (if any), if stderr is presented it's value
// will be wrapped as WorkerError. Method will return error code if php process fails
@@ -214,6 +182,33 @@ func (w *Worker) Exec(rqs *Payload) (rsp *Payload, err error) {
return rsp, err
}
+func (w *Worker) start() error {
+ if err := w.cmd.Start(); err != nil {
+ close(w.waitDone)
+
+ return err
+ }
+
+ w.Pid = &w.cmd.Process.Pid
+
+ // wait for process to complete
+ 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()
+ w.rl.Close()
+ }
+ }
+ }()
+
+ return nil
+}
+
func (w *Worker) execPayload(rqs *Payload) (rsp *Payload, err error) {
if err := sendHead(w.rl, rqs.Head); err != nil {
return nil, errors.Wrap(err, "header error")