From e18e782bba11f612a1996fb0acd606db55bb5dae Mon Sep 17 00:00:00 2001 From: mikespook Date: Mon, 4 Jun 2012 23:01:46 +0800 Subject: [PATCH] fixed grabbing jobs --- worker/agent.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/worker/agent.go b/worker/agent.go index 74d62e4..66bf4c1 100644 --- a/worker/agent.go +++ b/worker/agent.go @@ -7,6 +7,7 @@ package worker import ( "io" "net" + "time" "bitbucket.org/mikespook/gearman-go/common" ) @@ -57,12 +58,17 @@ func (a *agent) inLoop() { a.worker.removeAgent(a) }() noop := true + go func() { + for a.worker.running { + if noop && len(a.in) == 0 { + a.WriteJob(newJob(common.REQ, common.GRAB_JOB, nil)) + } + <-time.After(time.Second) + } + }() for a.worker.running { RESTART: // got noop msg and in queue is zero, grab job - if noop && len(a.in) == 0 { - a.WriteJob(newJob(common.REQ, common.GRAB_JOB, nil)) - } rel, err := a.read() if err != nil { if err == common.ErrConnection {