Пример #1
0
func (worker *Worker) dealJob(job *Job) {
	defer func() {
		job.Close()
		if worker.running && worker.limit != nil {
			<-worker.limit
		}
	}()
	switch job.DataType {
	case common.ERROR:
		_, err := common.GetError(job.Data)
		worker.err(err)
	case common.JOB_ASSIGN, common.JOB_ASSIGN_UNIQ:
		if err := worker.exec(job); err != nil {
			worker.err(err)
		}
	default:
		worker.handleJob(job)
	}
}
Пример #2
0
// in loop
func (client *Client) inLoop() {
	defer common.DisablePanic()
	for {
		rel, err := client.read()
		if err != nil {
			if err == common.ErrConnection {
				client.Close()
			}
			if err != common.ErrConnClosed {
				client.err(err)
			}
			break
		}
		job, err := decodeJob(rel)
		if err != nil {
			client.err(err)
			continue
			//break
		}
		switch job.DataType {
		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.ECHO_RES:
			client.handleEcho(job)
		case common.JOB_CREATED:
			client.handleCreated(job)
		case common.STATUS_RES:
			client.handleStatus(job)
		default:
			break
		}
	}
}