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 |
This commit is contained in:
		
							parent
							
								
									2002bb1804
								
							
						
					
					
						commit
						adbe320074
					
				| @ -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,13 +237,15 @@ 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) | ||||
|         if terminate { | ||||
|             delete(client.jobhandlers, job.Handle) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| func (client *Client) handleEcho(job *Job) { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user