mirror of
https://github.com/hibiken/asynq.git
synced 2025-08-19 15:08:55 +08:00
Change TaskMessage.ID type from uuid.UUID to string
This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/google/uuid"
|
||||
"github.com/hibiken/asynq/internal/base"
|
||||
"github.com/hibiken/asynq/internal/errors"
|
||||
"github.com/spf13/cast"
|
||||
@@ -386,21 +385,21 @@ var getTaskInfoCmd = redis.NewScript(`
|
||||
`)
|
||||
|
||||
// GetTaskInfo returns a TaskInfo describing the task from the given queue.
|
||||
func (r *RDB) GetTaskInfo(qname string, id uuid.UUID) (*base.TaskInfo, error) {
|
||||
func (r *RDB) GetTaskInfo(qname, id string) (*base.TaskInfo, error) {
|
||||
var op errors.Op = "rdb.GetTaskInfo"
|
||||
if err := r.checkQueueExists(qname); err != nil {
|
||||
return nil, errors.E(op, errors.CanonicalCode(err), err)
|
||||
}
|
||||
keys := []string{base.TaskKey(qname, id.String())}
|
||||
keys := []string{base.TaskKey(qname, id)}
|
||||
argv := []interface{}{
|
||||
id.String(),
|
||||
id,
|
||||
time.Now().Unix(),
|
||||
base.QueueKeyPrefix(qname),
|
||||
}
|
||||
res, err := getTaskInfoCmd.Run(context.Background(), r.client, keys, argv...).Result()
|
||||
if err != nil {
|
||||
if err.Error() == "NOT FOUND" {
|
||||
return nil, errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id.String()})
|
||||
return nil, errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id})
|
||||
}
|
||||
return nil, errors.E(op, errors.Unknown, err)
|
||||
}
|
||||
@@ -704,17 +703,17 @@ return 1
|
||||
// If a queue with the given name doesn't exist, it returns QueueNotFoundError.
|
||||
// If a task with the given id doesn't exist in the queue, it returns TaskNotFoundError
|
||||
// If a task is in active or pending state it returns non-nil error with Code FailedPrecondition.
|
||||
func (r *RDB) RunTask(qname string, id uuid.UUID) error {
|
||||
func (r *RDB) RunTask(qname, id string) error {
|
||||
var op errors.Op = "rdb.RunTask"
|
||||
if err := r.checkQueueExists(qname); err != nil {
|
||||
return errors.E(op, errors.CanonicalCode(err), err)
|
||||
}
|
||||
keys := []string{
|
||||
base.TaskKey(qname, id.String()),
|
||||
base.TaskKey(qname, id),
|
||||
base.PendingKey(qname),
|
||||
}
|
||||
argv := []interface{}{
|
||||
id.String(),
|
||||
id,
|
||||
base.QueueKeyPrefix(qname),
|
||||
}
|
||||
res, err := runTaskCmd.Run(context.Background(), r.client, keys, argv...).Result()
|
||||
@@ -729,7 +728,7 @@ func (r *RDB) RunTask(qname string, id uuid.UUID) error {
|
||||
case 1:
|
||||
return nil
|
||||
case 0:
|
||||
return errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id.String()})
|
||||
return errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id})
|
||||
case -1:
|
||||
return errors.E(op, errors.FailedPrecondition, "task is already running")
|
||||
case -2:
|
||||
@@ -922,18 +921,18 @@ return 1
|
||||
// If a task with the given id doesn't exist in the queue, it returns TaskNotFoundError
|
||||
// If a task is already archived, it returns TaskAlreadyArchivedError.
|
||||
// If a task is in active state it returns non-nil error with FailedPrecondition code.
|
||||
func (r *RDB) ArchiveTask(qname string, id uuid.UUID) error {
|
||||
func (r *RDB) ArchiveTask(qname, id string) error {
|
||||
var op errors.Op = "rdb.ArchiveTask"
|
||||
if err := r.checkQueueExists(qname); err != nil {
|
||||
return errors.E(op, errors.CanonicalCode(err), err)
|
||||
}
|
||||
keys := []string{
|
||||
base.TaskKey(qname, id.String()),
|
||||
base.TaskKey(qname, id),
|
||||
base.ArchivedKey(qname),
|
||||
}
|
||||
now := time.Now()
|
||||
argv := []interface{}{
|
||||
id.String(),
|
||||
id,
|
||||
now.Unix(),
|
||||
now.AddDate(0, 0, -archivedExpirationInDays).Unix(),
|
||||
maxArchiveSize,
|
||||
@@ -951,9 +950,9 @@ func (r *RDB) ArchiveTask(qname string, id uuid.UUID) error {
|
||||
case 1:
|
||||
return nil
|
||||
case 0:
|
||||
return errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id.String()})
|
||||
return errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id})
|
||||
case -1:
|
||||
return errors.E(op, errors.FailedPrecondition, &errors.TaskAlreadyArchivedError{Queue: qname, ID: id.String()})
|
||||
return errors.E(op, errors.FailedPrecondition, &errors.TaskAlreadyArchivedError{Queue: qname, ID: id})
|
||||
case -2:
|
||||
return errors.E(op, errors.FailedPrecondition, "cannot archive task in active state. use CancelTask instead.")
|
||||
case -3:
|
||||
@@ -1059,16 +1058,16 @@ return redis.call("DEL", KEYS[1])
|
||||
// If a queue with the given name doesn't exist, it returns QueueNotFoundError.
|
||||
// If a task with the given id doesn't exist in the queue, it returns TaskNotFoundError
|
||||
// If a task is in active state it returns non-nil error with Code FailedPrecondition.
|
||||
func (r *RDB) DeleteTask(qname string, id uuid.UUID) error {
|
||||
func (r *RDB) DeleteTask(qname, id string) error {
|
||||
var op errors.Op = "rdb.DeleteTask"
|
||||
if err := r.checkQueueExists(qname); err != nil {
|
||||
return errors.E(op, errors.CanonicalCode(err), err)
|
||||
}
|
||||
keys := []string{
|
||||
base.TaskKey(qname, id.String()),
|
||||
base.TaskKey(qname, id),
|
||||
}
|
||||
argv := []interface{}{
|
||||
id.String(),
|
||||
id,
|
||||
base.QueueKeyPrefix(qname),
|
||||
}
|
||||
res, err := deleteTaskCmd.Run(context.Background(), r.client, keys, argv...).Result()
|
||||
@@ -1083,7 +1082,7 @@ func (r *RDB) DeleteTask(qname string, id uuid.UUID) error {
|
||||
case 1:
|
||||
return nil
|
||||
case 0:
|
||||
return errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id.String()})
|
||||
return errors.E(op, errors.NotFound, &errors.TaskNotFoundError{Queue: qname, ID: id})
|
||||
case -1:
|
||||
return errors.E(op, errors.FailedPrecondition, "cannot delete task in active state. use CancelTask instead.")
|
||||
default:
|
||||
|
@@ -363,7 +363,7 @@ func TestGetTaskInfo(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
want *base.TaskInfo
|
||||
}{
|
||||
{
|
||||
@@ -478,7 +478,7 @@ func TestGetTaskInfoError(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
match func(err error) bool
|
||||
}{
|
||||
{
|
||||
@@ -488,7 +488,7 @@ func TestGetTaskInfoError(t *testing.T) {
|
||||
},
|
||||
{
|
||||
qname: "default",
|
||||
id: uuid.New(),
|
||||
id: uuid.NewString(),
|
||||
match: errors.IsTaskNotFound,
|
||||
},
|
||||
}
|
||||
@@ -882,7 +882,7 @@ func TestListRetry(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
m1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task1",
|
||||
Queue: "default",
|
||||
Payload: nil,
|
||||
@@ -891,7 +891,7 @@ func TestListRetry(t *testing.T) {
|
||||
Retried: 10,
|
||||
}
|
||||
m2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task2",
|
||||
Queue: "default",
|
||||
Payload: nil,
|
||||
@@ -900,7 +900,7 @@ func TestListRetry(t *testing.T) {
|
||||
Retried: 2,
|
||||
}
|
||||
m3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task3",
|
||||
Queue: "custom",
|
||||
Payload: nil,
|
||||
@@ -1041,21 +1041,21 @@ func TestListArchived(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
m1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task1",
|
||||
Queue: "default",
|
||||
Payload: nil,
|
||||
ErrorMsg: "some error occurred",
|
||||
}
|
||||
m2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task2",
|
||||
Queue: "default",
|
||||
Payload: nil,
|
||||
ErrorMsg: "some error occurred",
|
||||
}
|
||||
m3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task3",
|
||||
Queue: "custom",
|
||||
Payload: nil,
|
||||
@@ -1240,7 +1240,7 @@ func TestRunArchivedTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
archived map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantArchived map[string][]*base.TaskMessage
|
||||
wantPending map[string][]*base.TaskMessage
|
||||
}{
|
||||
@@ -1320,7 +1320,7 @@ func TestRunRetryTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
retry map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantRetry map[string][]*base.TaskMessage
|
||||
wantPending map[string][]*base.TaskMessage
|
||||
}{
|
||||
@@ -1400,7 +1400,7 @@ func TestRunScheduledTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
scheduled map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantScheduled map[string][]*base.TaskMessage
|
||||
wantPending map[string][]*base.TaskMessage
|
||||
}{
|
||||
@@ -1480,7 +1480,7 @@ func TestRunTaskError(t *testing.T) {
|
||||
pending map[string][]*base.TaskMessage
|
||||
scheduled map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
match func(err error) bool
|
||||
wantActive map[string][]*base.TaskMessage
|
||||
wantPending map[string][]*base.TaskMessage
|
||||
@@ -1526,7 +1526,7 @@ func TestRunTaskError(t *testing.T) {
|
||||
},
|
||||
},
|
||||
qname: "default",
|
||||
id: uuid.New(),
|
||||
id: uuid.NewString(),
|
||||
match: errors.IsTaskNotFound,
|
||||
wantActive: map[string][]*base.TaskMessage{
|
||||
"default": {},
|
||||
@@ -1987,7 +1987,7 @@ func TestArchiveRetryTask(t *testing.T) {
|
||||
retry map[string][]base.Z
|
||||
archived map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantRetry map[string][]base.Z
|
||||
wantArchived map[string][]base.Z
|
||||
}{
|
||||
@@ -2088,7 +2088,7 @@ func TestArchiveScheduledTask(t *testing.T) {
|
||||
scheduled map[string][]base.Z
|
||||
archived map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantScheduled map[string][]base.Z
|
||||
wantArchived map[string][]base.Z
|
||||
}{
|
||||
@@ -2185,7 +2185,7 @@ func TestArchivePendingTask(t *testing.T) {
|
||||
pending map[string][]*base.TaskMessage
|
||||
archived map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantPending map[string][]*base.TaskMessage
|
||||
wantArchived map[string][]base.Z
|
||||
}{
|
||||
@@ -2270,7 +2270,7 @@ func TestArchiveTaskError(t *testing.T) {
|
||||
scheduled map[string][]base.Z
|
||||
archived map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
match func(err error) bool
|
||||
wantActive map[string][]*base.TaskMessage
|
||||
wantScheduled map[string][]base.Z
|
||||
@@ -2312,7 +2312,7 @@ func TestArchiveTaskError(t *testing.T) {
|
||||
"default": {{Message: m2, Score: t2.Unix()}},
|
||||
},
|
||||
qname: "default",
|
||||
id: uuid.New(),
|
||||
id: uuid.NewString(),
|
||||
match: errors.IsTaskNotFound,
|
||||
wantActive: map[string][]*base.TaskMessage{
|
||||
"default": {},
|
||||
@@ -2879,7 +2879,7 @@ func TestDeleteArchivedTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
archived map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantArchived map[string][]*base.TaskMessage
|
||||
}{
|
||||
{
|
||||
@@ -2945,7 +2945,7 @@ func TestDeleteRetryTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
retry map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantRetry map[string][]*base.TaskMessage
|
||||
}{
|
||||
{
|
||||
@@ -3011,7 +3011,7 @@ func TestDeleteScheduledTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
scheduled map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantScheduled map[string][]*base.TaskMessage
|
||||
}{
|
||||
{
|
||||
@@ -3074,7 +3074,7 @@ func TestDeletePendingTask(t *testing.T) {
|
||||
tests := []struct {
|
||||
pending map[string][]*base.TaskMessage
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
wantPending map[string][]*base.TaskMessage
|
||||
}{
|
||||
{
|
||||
@@ -3123,7 +3123,7 @@ func TestDeleteTaskWithUniqueLock(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
m1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "email",
|
||||
Payload: h.JSON(map[string]interface{}{"user_id": json.Number("123")}),
|
||||
Queue: base.DefaultQueueName,
|
||||
@@ -3134,7 +3134,7 @@ func TestDeleteTaskWithUniqueLock(t *testing.T) {
|
||||
tests := []struct {
|
||||
scheduled map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
uniqueKey string
|
||||
wantScheduled map[string][]*base.TaskMessage
|
||||
}{
|
||||
@@ -3186,7 +3186,7 @@ func TestDeleteTaskError(t *testing.T) {
|
||||
active map[string][]*base.TaskMessage
|
||||
scheduled map[string][]base.Z
|
||||
qname string
|
||||
id uuid.UUID
|
||||
id string
|
||||
match func(err error) bool
|
||||
wantActive map[string][]*base.TaskMessage
|
||||
wantScheduled map[string][]*base.TaskMessage
|
||||
@@ -3200,7 +3200,7 @@ func TestDeleteTaskError(t *testing.T) {
|
||||
"default": {{Message: m1, Score: t1.Unix()}},
|
||||
},
|
||||
qname: "default",
|
||||
id: uuid.New(),
|
||||
id: uuid.NewString(),
|
||||
match: errors.IsTaskNotFound,
|
||||
wantActive: map[string][]*base.TaskMessage{
|
||||
"default": {},
|
||||
@@ -3218,7 +3218,7 @@ func TestDeleteTaskError(t *testing.T) {
|
||||
"default": {{Message: m1, Score: t1.Unix()}},
|
||||
},
|
||||
qname: "nonexistent",
|
||||
id: uuid.New(),
|
||||
id: uuid.NewString(),
|
||||
match: errors.IsQueueNotFound,
|
||||
wantActive: map[string][]*base.TaskMessage{
|
||||
"default": {},
|
||||
@@ -3340,7 +3340,7 @@ func TestDeleteAllArchivedTasksWithUniqueKey(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
m1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task1",
|
||||
Payload: nil,
|
||||
Timeout: 1800,
|
||||
@@ -3349,7 +3349,7 @@ func TestDeleteAllArchivedTasksWithUniqueKey(t *testing.T) {
|
||||
Queue: "default",
|
||||
}
|
||||
m2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "task2",
|
||||
Payload: nil,
|
||||
Timeout: 1800,
|
||||
@@ -3721,7 +3721,7 @@ func TestRemoveQueue(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
if n := len(r.client.Keys(context.Background(), base.TaskKeyPrefix(tc.qname) + "*").Val()); n != 0 {
|
||||
if n := len(r.client.Keys(context.Background(), base.TaskKeyPrefix(tc.qname)+"*").Val()); n != 0 {
|
||||
t.Errorf("%d keys still exists for tasks", n)
|
||||
}
|
||||
}
|
||||
@@ -3960,7 +3960,7 @@ func TestListWorkers(t *testing.T) {
|
||||
Host: host,
|
||||
PID: pid,
|
||||
ServerID: serverID,
|
||||
ID: m1.ID.String(),
|
||||
ID: m1.ID,
|
||||
Type: m1.Type,
|
||||
Queue: m1.Queue,
|
||||
Payload: m1.Payload,
|
||||
@@ -3971,7 +3971,7 @@ func TestListWorkers(t *testing.T) {
|
||||
Host: host,
|
||||
PID: pid,
|
||||
ServerID: serverID,
|
||||
ID: m2.ID.String(),
|
||||
ID: m2.ID,
|
||||
Type: m2.Type,
|
||||
Queue: m2.Queue,
|
||||
Payload: m2.Payload,
|
||||
@@ -3982,7 +3982,7 @@ func TestListWorkers(t *testing.T) {
|
||||
Host: host,
|
||||
PID: pid,
|
||||
ServerID: serverID,
|
||||
ID: m3.ID.String(),
|
||||
ID: m3.ID,
|
||||
Type: m3.Type,
|
||||
Queue: m3.Queue,
|
||||
Payload: m3.Payload,
|
||||
|
@@ -84,12 +84,12 @@ func (r *RDB) Enqueue(msg *base.TaskMessage) error {
|
||||
return errors.E(op, errors.Unknown, &errors.RedisCommandError{Command: "sadd", Err: err})
|
||||
}
|
||||
keys := []string{
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.PendingKey(msg.Queue),
|
||||
}
|
||||
argv := []interface{}{
|
||||
encoded,
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
msg.Timeout,
|
||||
msg.Deadline,
|
||||
}
|
||||
@@ -139,11 +139,11 @@ func (r *RDB) EnqueueUnique(msg *base.TaskMessage, ttl time.Duration) error {
|
||||
}
|
||||
keys := []string{
|
||||
msg.UniqueKey,
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.PendingKey(msg.Queue),
|
||||
}
|
||||
argv := []interface{}{
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
int(ttl.Seconds()),
|
||||
encoded,
|
||||
msg.Timeout,
|
||||
@@ -312,11 +312,11 @@ func (r *RDB) Done(msg *base.TaskMessage) error {
|
||||
keys := []string{
|
||||
base.ActiveKey(msg.Queue),
|
||||
base.DeadlinesKey(msg.Queue),
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.ProcessedKey(msg.Queue, now),
|
||||
}
|
||||
argv := []interface{}{
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
expireAt.Unix(),
|
||||
}
|
||||
if len(msg.UniqueKey) > 0 {
|
||||
@@ -350,9 +350,9 @@ func (r *RDB) Requeue(msg *base.TaskMessage) error {
|
||||
base.ActiveKey(msg.Queue),
|
||||
base.DeadlinesKey(msg.Queue),
|
||||
base.PendingKey(msg.Queue),
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
}
|
||||
return r.runScript(op, requeueCmd, keys, msg.ID.String())
|
||||
return r.runScript(op, requeueCmd, keys, msg.ID)
|
||||
}
|
||||
|
||||
// KEYS[1] -> asynq:{<qname>}:t:<task_id>
|
||||
@@ -383,13 +383,13 @@ func (r *RDB) Schedule(msg *base.TaskMessage, processAt time.Time) error {
|
||||
return errors.E(op, errors.Unknown, &errors.RedisCommandError{Command: "sadd", Err: err})
|
||||
}
|
||||
keys := []string{
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.ScheduledKey(msg.Queue),
|
||||
}
|
||||
argv := []interface{}{
|
||||
encoded,
|
||||
processAt.Unix(),
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
msg.Timeout,
|
||||
msg.Deadline,
|
||||
}
|
||||
@@ -433,11 +433,11 @@ func (r *RDB) ScheduleUnique(msg *base.TaskMessage, processAt time.Time, ttl tim
|
||||
}
|
||||
keys := []string{
|
||||
msg.UniqueKey,
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.ScheduledKey(msg.Queue),
|
||||
}
|
||||
argv := []interface{}{
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
int(ttl.Seconds()),
|
||||
processAt.Unix(),
|
||||
encoded,
|
||||
@@ -508,7 +508,7 @@ func (r *RDB) Retry(msg *base.TaskMessage, processAt time.Time, errMsg string, i
|
||||
}
|
||||
expireAt := now.Add(statsTTL)
|
||||
keys := []string{
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.ActiveKey(msg.Queue),
|
||||
base.DeadlinesKey(msg.Queue),
|
||||
base.RetryKey(msg.Queue),
|
||||
@@ -516,7 +516,7 @@ func (r *RDB) Retry(msg *base.TaskMessage, processAt time.Time, errMsg string, i
|
||||
base.FailedKey(msg.Queue, now),
|
||||
}
|
||||
argv := []interface{}{
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
encoded,
|
||||
processAt.Unix(),
|
||||
expireAt.Unix(),
|
||||
@@ -578,7 +578,7 @@ func (r *RDB) Archive(msg *base.TaskMessage, errMsg string) error {
|
||||
cutoff := now.AddDate(0, 0, -archivedExpirationInDays)
|
||||
expireAt := now.Add(statsTTL)
|
||||
keys := []string{
|
||||
base.TaskKey(msg.Queue, msg.ID.String()),
|
||||
base.TaskKey(msg.Queue, msg.ID),
|
||||
base.ActiveKey(msg.Queue),
|
||||
base.DeadlinesKey(msg.Queue),
|
||||
base.ArchivedKey(msg.Queue),
|
||||
@@ -586,7 +586,7 @@ func (r *RDB) Archive(msg *base.TaskMessage, errMsg string) error {
|
||||
base.FailedKey(msg.Queue, now),
|
||||
}
|
||||
argv := []interface{}{
|
||||
msg.ID.String(),
|
||||
msg.ID,
|
||||
encoded,
|
||||
now.Unix(),
|
||||
cutoff.Unix(),
|
||||
|
@@ -91,13 +91,13 @@ func TestEnqueue(t *testing.T) {
|
||||
t.Errorf("Redis LIST %q contains %d IDs, want 1", pendingKey, n)
|
||||
continue
|
||||
}
|
||||
if pendingIDs[0] != tc.msg.ID.String() {
|
||||
t.Errorf("Redis LIST %q: got %v, want %v", pendingKey, pendingIDs, []string{tc.msg.ID.String()})
|
||||
if pendingIDs[0] != tc.msg.ID {
|
||||
t.Errorf("Redis LIST %q: got %v, want %v", pendingKey, pendingIDs, []string{tc.msg.ID})
|
||||
continue
|
||||
}
|
||||
|
||||
// Check the value under the task key.
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID.String())
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID)
|
||||
encoded := r.client.HGet(context.Background(), taskKey, "msg").Val() // "msg" field
|
||||
decoded := h.MustUnmarshal(t, encoded)
|
||||
if diff := cmp.Diff(tc.msg, decoded); diff != "" {
|
||||
@@ -127,7 +127,7 @@ func TestEnqueueUnique(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
m1 := base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "email",
|
||||
Payload: h.JSON(map[string]interface{}{"user_id": json.Number("123")}),
|
||||
Queue: base.DefaultQueueName,
|
||||
@@ -170,13 +170,13 @@ func TestEnqueueUnique(t *testing.T) {
|
||||
t.Errorf("Redis LIST %q contains %d IDs, want 1", pendingKey, len(pendingIDs))
|
||||
continue
|
||||
}
|
||||
if pendingIDs[0] != tc.msg.ID.String() {
|
||||
t.Errorf("Redis LIST %q: got %v, want %v", pendingKey, pendingIDs, []string{tc.msg.ID.String()})
|
||||
if pendingIDs[0] != tc.msg.ID {
|
||||
t.Errorf("Redis LIST %q: got %v, want %v", pendingKey, pendingIDs, []string{tc.msg.ID})
|
||||
continue
|
||||
}
|
||||
|
||||
// Check the value under the task key.
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID.String())
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID)
|
||||
encoded := r.client.HGet(context.Background(), taskKey, "msg").Val() // "msg" field
|
||||
decoded := h.MustUnmarshal(t, encoded)
|
||||
if diff := cmp.Diff(tc.msg, decoded); diff != "" {
|
||||
@@ -223,7 +223,7 @@ func TestDequeue(t *testing.T) {
|
||||
defer r.Close()
|
||||
now := time.Now()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: h.JSON(map[string]interface{}{"subject": "hello!"}),
|
||||
Queue: "default",
|
||||
@@ -232,7 +232,7 @@ func TestDequeue(t *testing.T) {
|
||||
}
|
||||
t1Deadline := now.Unix() + t1.Timeout
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "export_csv",
|
||||
Payload: nil,
|
||||
Queue: "critical",
|
||||
@@ -241,7 +241,7 @@ func TestDequeue(t *testing.T) {
|
||||
}
|
||||
t2Deadline := t2.Deadline
|
||||
t3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "reindex",
|
||||
Payload: nil,
|
||||
Queue: "low",
|
||||
@@ -466,7 +466,7 @@ func TestDequeueIgnoresPausedQueues(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: h.JSON(map[string]interface{}{"subject": "hello!"}),
|
||||
Queue: "default",
|
||||
@@ -474,7 +474,7 @@ func TestDequeueIgnoresPausedQueues(t *testing.T) {
|
||||
Deadline: 0,
|
||||
}
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "export_csv",
|
||||
Payload: nil,
|
||||
Queue: "critical",
|
||||
@@ -580,7 +580,7 @@ func TestDone(t *testing.T) {
|
||||
defer r.Close()
|
||||
now := time.Now()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: nil,
|
||||
Timeout: 1800,
|
||||
@@ -588,7 +588,7 @@ func TestDone(t *testing.T) {
|
||||
Queue: "default",
|
||||
}
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "export_csv",
|
||||
Payload: nil,
|
||||
Timeout: 0,
|
||||
@@ -596,7 +596,7 @@ func TestDone(t *testing.T) {
|
||||
Queue: "custom",
|
||||
}
|
||||
t3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "reindex",
|
||||
Payload: nil,
|
||||
Timeout: 1800,
|
||||
@@ -682,7 +682,7 @@ func TestDone(t *testing.T) {
|
||||
for _, msg := range msgs {
|
||||
// Set uniqueness lock if unique key is present.
|
||||
if len(msg.UniqueKey) > 0 {
|
||||
err := r.client.SetNX(context.Background(), msg.UniqueKey, msg.ID.String(), time.Minute).Err()
|
||||
err := r.client.SetNX(context.Background(), msg.UniqueKey, msg.ID, time.Minute).Err()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -733,21 +733,21 @@ func TestRequeue(t *testing.T) {
|
||||
defer r.Close()
|
||||
now := time.Now()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: nil,
|
||||
Queue: "default",
|
||||
Timeout: 1800,
|
||||
}
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "export_csv",
|
||||
Payload: nil,
|
||||
Queue: "default",
|
||||
Timeout: 3000,
|
||||
}
|
||||
t3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: nil,
|
||||
Queue: "critical",
|
||||
@@ -906,9 +906,9 @@ func TestSchedule(t *testing.T) {
|
||||
scheduledKey, n)
|
||||
continue
|
||||
}
|
||||
if got := zs[0].Member.(string); got != tc.msg.ID.String() {
|
||||
if got := zs[0].Member.(string); got != tc.msg.ID {
|
||||
t.Errorf("Redis ZSET %q member: got %v, want %v",
|
||||
scheduledKey, got, tc.msg.ID.String())
|
||||
scheduledKey, got, tc.msg.ID)
|
||||
continue
|
||||
}
|
||||
if got := int64(zs[0].Score); got != tc.processAt.Unix() {
|
||||
@@ -918,7 +918,7 @@ func TestSchedule(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check the values under the task key.
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID.String())
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID)
|
||||
encoded := r.client.HGet(context.Background(), taskKey, "msg").Val() // "msg" field
|
||||
decoded := h.MustUnmarshal(t, encoded)
|
||||
if diff := cmp.Diff(tc.msg, decoded); diff != "" {
|
||||
@@ -950,7 +950,7 @@ func TestScheduleUnique(t *testing.T) {
|
||||
r := setup(t)
|
||||
defer r.Close()
|
||||
m1 := base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "email",
|
||||
Payload: h.JSON(map[string]interface{}{"user_id": 123}),
|
||||
Queue: base.DefaultQueueName,
|
||||
@@ -983,9 +983,9 @@ func TestScheduleUnique(t *testing.T) {
|
||||
scheduledKey, n)
|
||||
continue
|
||||
}
|
||||
if got := zs[0].Member.(string); got != tc.msg.ID.String() {
|
||||
if got := zs[0].Member.(string); got != tc.msg.ID {
|
||||
t.Errorf("Redis ZSET %q member: got %v, want %v",
|
||||
scheduledKey, got, tc.msg.ID.String())
|
||||
scheduledKey, got, tc.msg.ID)
|
||||
continue
|
||||
}
|
||||
if got := int64(zs[0].Score); got != tc.processAt.Unix() {
|
||||
@@ -995,7 +995,7 @@ func TestScheduleUnique(t *testing.T) {
|
||||
}
|
||||
|
||||
// Check the values under the task key.
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID.String())
|
||||
taskKey := base.TaskKey(tc.msg.Queue, tc.msg.ID)
|
||||
encoded := r.client.HGet(context.Background(), taskKey, "msg").Val() // "msg" field
|
||||
decoded := h.MustUnmarshal(t, encoded)
|
||||
if diff := cmp.Diff(tc.msg, decoded); diff != "" {
|
||||
@@ -1045,7 +1045,7 @@ func TestRetry(t *testing.T) {
|
||||
defer r.Close()
|
||||
now := time.Now()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: h.JSON(map[string]interface{}{"subject": "Hola!"}),
|
||||
Retried: 10,
|
||||
@@ -1053,21 +1053,21 @@ func TestRetry(t *testing.T) {
|
||||
Queue: "default",
|
||||
}
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "gen_thumbnail",
|
||||
Payload: h.JSON(map[string]interface{}{"path": "some/path/to/image.jpg"}),
|
||||
Timeout: 3000,
|
||||
Queue: "default",
|
||||
}
|
||||
t3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "reindex",
|
||||
Payload: nil,
|
||||
Timeout: 60,
|
||||
Queue: "default",
|
||||
}
|
||||
t4 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_notification",
|
||||
Payload: nil,
|
||||
Timeout: 1800,
|
||||
@@ -1216,7 +1216,7 @@ func TestRetryWithNonFailureError(t *testing.T) {
|
||||
defer r.Close()
|
||||
now := time.Now()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: h.JSON(map[string]interface{}{"subject": "Hola!"}),
|
||||
Retried: 10,
|
||||
@@ -1224,21 +1224,21 @@ func TestRetryWithNonFailureError(t *testing.T) {
|
||||
Queue: "default",
|
||||
}
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "gen_thumbnail",
|
||||
Payload: h.JSON(map[string]interface{}{"path": "some/path/to/image.jpg"}),
|
||||
Timeout: 3000,
|
||||
Queue: "default",
|
||||
}
|
||||
t3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "reindex",
|
||||
Payload: nil,
|
||||
Timeout: 60,
|
||||
Queue: "default",
|
||||
}
|
||||
t4 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_notification",
|
||||
Payload: nil,
|
||||
Timeout: 1800,
|
||||
@@ -1383,7 +1383,7 @@ func TestArchive(t *testing.T) {
|
||||
defer r.Close()
|
||||
now := time.Now()
|
||||
t1 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: nil,
|
||||
Queue: "default",
|
||||
@@ -1393,7 +1393,7 @@ func TestArchive(t *testing.T) {
|
||||
}
|
||||
t1Deadline := now.Unix() + t1.Timeout
|
||||
t2 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "reindex",
|
||||
Payload: nil,
|
||||
Queue: "default",
|
||||
@@ -1403,7 +1403,7 @@ func TestArchive(t *testing.T) {
|
||||
}
|
||||
t2Deadline := now.Unix() + t2.Timeout
|
||||
t3 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "generate_csv",
|
||||
Payload: nil,
|
||||
Queue: "default",
|
||||
@@ -1413,7 +1413,7 @@ func TestArchive(t *testing.T) {
|
||||
}
|
||||
t3Deadline := now.Unix() + t3.Timeout
|
||||
t4 := &base.TaskMessage{
|
||||
ID: uuid.New(),
|
||||
ID: uuid.NewString(),
|
||||
Type: "send_email",
|
||||
Payload: nil,
|
||||
Queue: "custom",
|
||||
@@ -1905,7 +1905,7 @@ func TestWriteServerStateWithWorkers(t *testing.T) {
|
||||
{
|
||||
Host: host,
|
||||
PID: pid,
|
||||
ID: msg1.ID.String(),
|
||||
ID: msg1.ID,
|
||||
Type: msg1.Type,
|
||||
Queue: msg1.Queue,
|
||||
Payload: msg1.Payload,
|
||||
@@ -1914,7 +1914,7 @@ func TestWriteServerStateWithWorkers(t *testing.T) {
|
||||
{
|
||||
Host: host,
|
||||
PID: pid,
|
||||
ID: msg2.ID.String(),
|
||||
ID: msg2.ID,
|
||||
Type: msg2.Type,
|
||||
Queue: msg2.Queue,
|
||||
Payload: msg2.Payload,
|
||||
@@ -2017,7 +2017,7 @@ func TestClearServerState(t *testing.T) {
|
||||
{
|
||||
Host: host,
|
||||
PID: pid,
|
||||
ID: msg1.ID.String(),
|
||||
ID: msg1.ID,
|
||||
Type: msg1.Type,
|
||||
Queue: msg1.Queue,
|
||||
Payload: msg1.Payload,
|
||||
@@ -2040,7 +2040,7 @@ func TestClearServerState(t *testing.T) {
|
||||
{
|
||||
Host: otherHost,
|
||||
PID: otherPID,
|
||||
ID: msg2.ID.String(),
|
||||
ID: msg2.ID,
|
||||
Type: msg2.Type,
|
||||
Queue: msg2.Queue,
|
||||
Payload: msg2.Payload,
|
||||
|
Reference in New Issue
Block a user