示例#1
0
文件: queue.go 项目: coseyo/uniqueue
// getKeyByJob return the job key by job type
func (q *Queue) getKeyByJob(job []byte) (jobKey []byte, err error) {
	var (
		iface  interface{}
		jobMap map[string]interface{}
	)

	if json.Unmarshal(job, &iface) == nil {
		jobMap, err = getMap(iface)
		if err != nil {
			return
		}
		jobKey = sortmap.MapToMD5(jobMap)
	} else {
		jobKey = job
	}

	return
}
示例#2
0
文件: queue.go 项目: coseyo/uniqueue
// parseJob parse job to key
func (q *Queue) parseJob(job interface{}) (jobKey []byte, jobContent []byte, err error) {
	jobValue := reflect.ValueOf(job)
	jobIface := jobValue.Interface()
	if jobValue.Kind() == reflect.Map {
		var jobMap map[string]interface{}
		jobMap, err = getMap(jobIface)
		if err != nil {
			return
		}
		jobKey = sortmap.MapToMD5(jobMap)
		jobContent, err = json.Marshal(jobMap)
	} else {
		jobKey = getBytes(job)
		jobContent = jobKey
	}

	return
}