From adbe320074553d677c7ae791d33950cb7f7208dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Sat, 9 Nov 2013 09:27:30 -0800 Subject: [PATCH] Remove handle only when the job is done This commit stops the client from removing the job handle from client.jobhandlers when the worker has sent an update (e.g. WORK_STATUS) without terminating its life. WORK_DATA | WORK_WARNING | => Notification WORK_STATUS | WORK_COMPLETE | WORK_FAIL | => Notification + End of life WORK_EXCEPTION | --- client/client.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index cdfdd5f..57f7760 100644 --- a/client/client.go +++ b/client/client.go @@ -213,9 +213,10 @@ func (client *Client) inLoop() { case common.ERROR: _, err := common.GetError(job.Data) client.err(err) - case common.WORK_DATA, common.WORK_WARNING, common.WORK_STATUS, - common.WORK_COMPLETE, common.WORK_FAIL, common.WORK_EXCEPTION: - client.handleJob(job) + case common.WORK_DATA, common.WORK_WARNING, common.WORK_STATUS: + client.handleJob(job, false) + case common.WORK_COMPLETE, common.WORK_FAIL, common.WORK_EXCEPTION: + client.handleJob(job, true) case common.ECHO_RES: client.handleEcho(job) case common.JOB_CREATED: @@ -236,12 +237,14 @@ func (client *Client) err (e error) { } // job handler -func (client *Client) handleJob(job *Job) { +func (client *Client) handleJob(job *Job, terminate bool) { client.mutex.RLock() defer client.mutex.RUnlock() if h, ok := client.jobhandlers[job.Handle]; ok { h(job) - delete(client.jobhandlers, job.Handle) + if terminate { + delete(client.jobhandlers, job.Handle) + } } }