fixed the closing method
This commit is contained in:
parent
d32eb195e1
commit
a003eac543
@ -30,7 +30,6 @@ type Worker struct {
|
|||||||
limit chan bool
|
limit chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Return a worker.
|
// Return a worker.
|
||||||
//
|
//
|
||||||
// If limit is set to Unlimited(=0), the worker will grab all jobs
|
// If limit is set to Unlimited(=0), the worker will grab all jobs
|
||||||
@ -99,7 +98,7 @@ func (worker *Worker) addFunc(funcname string, timeout uint32) {
|
|||||||
worker.broadcast(outpack)
|
worker.broadcast(outpack)
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepFuncOutpack(funcname string, timeout uint32) (*outPack){
|
func prepFuncOutpack(funcname string, timeout uint32) *outPack {
|
||||||
outpack := getOutPack()
|
outpack := getOutPack()
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
outpack.dataType = dtCanDo
|
outpack.dataType = dtCanDo
|
||||||
@ -196,11 +195,6 @@ func (worker *Worker) Work() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
|
||||||
for _, a := range worker.agents {
|
|
||||||
a.Close()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
worker.running = true
|
worker.running = true
|
||||||
for _, a := range worker.agents {
|
for _, a := range worker.agents {
|
||||||
a.Grab()
|
a.Grab()
|
||||||
@ -223,8 +217,11 @@ func (worker *Worker) customeHandler(inpack *inPack) {
|
|||||||
// Close connection and exit main loop
|
// Close connection and exit main loop
|
||||||
func (worker *Worker) Close() {
|
func (worker *Worker) Close() {
|
||||||
worker.Lock()
|
worker.Lock()
|
||||||
worker.Unlock()
|
defer worker.Unlock()
|
||||||
if worker.running == true {
|
if worker.running == true {
|
||||||
|
for _, a := range worker.agents {
|
||||||
|
a.Close()
|
||||||
|
}
|
||||||
worker.running = false
|
worker.running = false
|
||||||
close(worker.in)
|
close(worker.in)
|
||||||
}
|
}
|
||||||
@ -337,14 +334,16 @@ type WorkerDisconnectError struct{
|
|||||||
err error
|
err error
|
||||||
agent *agent
|
agent *agent
|
||||||
}
|
}
|
||||||
func (e *WorkerDisconnectError) Error() ( string){
|
|
||||||
return e.err.Error();
|
func (e *WorkerDisconnectError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Responds to the error by asking the worker to reconnect
|
// Responds to the error by asking the worker to reconnect
|
||||||
func (e *WorkerDisconnectError) Reconnect() (err error) {
|
func (e *WorkerDisconnectError) Reconnect() (err error) {
|
||||||
return e.agent.reconnect()
|
return e.agent.reconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Which server was this for?
|
// Which server was this for?
|
||||||
func (e *WorkerDisconnectError) Server() (net string, addr string) {
|
func (e *WorkerDisconnectError) Server() (net string, addr string) {
|
||||||
return e.agent.net, e.agent.addr
|
return e.agent.net, e.agent.addr
|
||||||
|
Loading…
Reference in New Issue
Block a user