summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-01-28 14:35:07 +0300
committerWolfy-J <[email protected]>2018-01-28 14:35:07 +0300
commitc57232ae2bc7253ded326226948dfc7f9b324753 (patch)
treea7710545a75f9ecf483618ff742f55ed8a0d5fae
parente4e5cadce7deef4c36c038a4900d55ea30dd099c (diff)
golint
-rw-r--r--payload.go10
-rw-r--r--pool.go6
-rw-r--r--worker.go7
3 files changed, 14 insertions, 9 deletions
diff --git a/payload.go b/payload.go
index 63a709dc..8b029e1d 100644
--- a/payload.go
+++ b/payload.go
@@ -1,11 +1,13 @@
package roadrunner
+// Payload carries binary header and body to workers and
+// back to the server.
type Payload struct {
- Head, Body []byte
-}
-
-func (p *Payload) HeadString() {
+ // Head represent payload context, might be omitted
+ Head []byte
+ // Body contains binary payload to be processed by worker
+ Body []byte
}
// String returns payload body as string
diff --git a/pool.go b/pool.go
index 21637bef..ec508c93 100644
--- a/pool.go
+++ b/pool.go
@@ -10,8 +10,8 @@ import (
)
const (
- // Control header to be made by worker to request termination.
- TerminateRequest = "{\"terminate\": true}"
+ // StopRequest can be sent by worker to indicate that restart is required.
+ StopRequest = "{\"stop\": true}"
)
// Pool controls worker creation, destruction and task routing.
@@ -123,7 +123,7 @@ func (p *Pool) Exec(rqs *Payload) (rsp *Payload, err error) {
}
// worker want's to be terminated
- if rsp.Body == nil && rsp.Head != nil && string(rsp.Head) == TerminateRequest {
+ if rsp.Body == nil && rsp.Head != nil && string(rsp.Head) == StopRequest {
go p.replaceWorker(w, err)
return p.Exec(rqs)
}
diff --git a/worker.go b/worker.go
index 851239f9..d505c54b 100644
--- a/worker.go
+++ b/worker.go
@@ -148,7 +148,7 @@ func (w *Worker) Wait() error {
return &exec.ExitError{ProcessState: w.endState}
}
-// Destroy sends soft termination command to the worker to properly stop the process.
+// Stop sends soft termination command to the worker and waits for process completion.
func (w *Worker) Stop() error {
select {
case <-w.waitDone:
@@ -166,7 +166,7 @@ func (w *Worker) Stop() error {
}
// Kill kills underlying process, make sure to call Wait() func to gather
-// error log from the stderr
+// error log from the stderr. Waits for process completion.
func (w *Worker) Kill() error {
select {
case <-w.waitDone:
@@ -183,6 +183,9 @@ func (w *Worker) Kill() error {
}
}
+// Exec sends payload to worker, executes it and returns result or
+// error. Make sure to handle worker.Wait() to gather worker level
+// 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()