Use md5 to generate checksum for unique key

This commit is contained in:
Ken Hibino
2021-06-09 06:46:21 -07:00
parent d1aa247927
commit 9f9870ee25
2 changed files with 30 additions and 22 deletions

View File

@@ -7,6 +7,8 @@ package base
import (
"context"
"crypto/md5"
"encoding/hex"
"fmt"
"sync"
"time"
@@ -170,9 +172,12 @@ func SchedulerHistoryKey(entryID string) string {
}
// UniqueKey returns a redis key with the given type, payload, and queue name.
// FIXME: We probably need to generate a hash of payload to make this key unique
func UniqueKey(qname, tasktype string, payload []byte) string {
return fmt.Sprintf("%sunique:%s:%s", QueueKeyPrefix(qname), tasktype, string(payload))
if payload == nil {
return fmt.Sprintf("%sunique:%s:", QueueKeyPrefix(qname), tasktype)
}
checksum := md5.Sum(payload)
return fmt.Sprintf("%sunique:%s:%s", QueueKeyPrefix(qname), tasktype, hex.EncodeToString(checksum[:]))
}
// TaskMessage is the internal representation of a task with additional metadata fields.