Beispiel #1
0
// 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
}
Beispiel #2
0
// 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
}