调用Close后不再向JobServer获取任务

This commit is contained in:
余 欣怀 2023-02-13 01:01:37 +08:00
parent 97187ecbf9
commit abd6ce9be3
2 changed files with 9 additions and 4 deletions

View File

@ -143,10 +143,14 @@ func (a *agent) Grab() {
a.grab() a.grab()
} }
func (a *agent) grab() { func (a *agent) grab() bool {
if a.worker.closed != nil {
return false
}
outpack := getOutPack() outpack := getOutPack()
outpack.dataType = dtGrabJobUniq outpack.dataType = dtGrabJobUniq
a.write(outpack) a.write(outpack)
return true
} }
func (a *agent) PreSleep() { func (a *agent) PreSleep() {
@ -169,9 +173,10 @@ func (a *agent) reconnect() error {
bufio.NewWriter(a.conn)) bufio.NewWriter(a.conn))
a.worker.reRegisterFuncsForAgent(a) a.worker.reRegisterFuncsForAgent(a)
a.grab() if a.grab() {
go a.work()
}
go a.work()
return nil return nil
} }

View File

@ -344,7 +344,7 @@ func (worker *Worker) exec(inpack *inPack) (err error) {
} }
outpack.handle = inpack.handle outpack.handle = inpack.handle
outpack.data = r.data outpack.data = r.data
err = inpack.a.Write(outpack) _ = inpack.a.Write(outpack)
if worker.leftJobs != nil { if worker.leftJobs != nil {
worker.leftJobs <- struct{}{} worker.leftJobs <- struct{}{}
} }