Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/backend/redis/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package redis
import (
"context"
"encoding/json"
"fmt"
"reflect"
"time"

Expand Down Expand Up @@ -271,8 +272,10 @@ func (b *Backend) ensureQueueExistsByUID(rds redis.Cmdable, uid string) (*taskqu
rawQueue, err := rds.Get(b.queueKey(uid)).Result()
switch {
case err == redis.Nil:
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("GET %s", b.queueKey(uid))).Msg("debug-next-task")
return nil, iface.TaskQueueNotFound
case err != nil:
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("GET %s", b.queueKey(uid))).Msg("debug-next-task")
return nil, err
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/backend/redis/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ func (b *Backend) NextTask(ctx context.Context, queueUID, workerUID uuid.UUID) (
toPop := false
numWorkerPending, err := tx.LLen(workerPendingQueueKey).Result()
if err == redis.Nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("LLEN %s", workerPendingQueueKey)).Msg("debug-next-task")
toPop = true
}
if err != nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("LLEN %s", workerPendingQueueKey)).Msg("debug-next-task")
return err
}
if numWorkerPending == 0 {
Expand All @@ -413,11 +415,13 @@ func (b *Backend) NextTask(ctx context.Context, queueUID, workerUID uuid.UUID) (
return nil
})
if err == redis.Nil {
b.Logger.Error().Stack().Err(err).Msg("debug-next-task: this should not happen.")
return backoff.Permanent(iface.TaskQueueEmptyError)
}
return err
}, queueKey, workerPendingQueueKey)
if err != nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("MULTI; RPOPLPUSH %s %s; EXEC", pendingQueueKey, workerPendingQueueKey)).Msg("debug-next-task")
return nil, err
}

Expand Down Expand Up @@ -454,9 +458,11 @@ func (b *Backend) NextTask(ctx context.Context, queueUID, workerUID uuid.UUID) (
// peak worker pending queue
taskUIDs, err := tx.LRange(workerPendingQueueKey, -1, -1).Result()
if err == redis.Nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("LRANGE %s -1 -1", workerPendingQueueKey)).Msg("debug-next-task")
return backoff.Permanent(iface.TaskQueueEmptyError)
}
if err != nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("LRANGE %s -1 -1", workerPendingQueueKey)).Msg("debug-next-task")
return err
}
if len(taskUIDs) == 0 {
Expand All @@ -466,6 +472,7 @@ func (b *Backend) NextTask(ctx context.Context, queueUID, workerUID uuid.UUID) (
// get Task and transit to Received
raw, err := tx.Get(b.taskKey(queue.UID.String(), taskUIDs[0])).Result()
if err != nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("Get %s", b.taskKey(queue.UID.String(), taskUIDs[0]))).Msg("debug-next-task")
return err
}
t = &task.Task{}
Expand Down Expand Up @@ -504,6 +511,7 @@ func (b *Backend) NextTask(ctx context.Context, queueUID, workerUID uuid.UUID) (
workerPendingQueueKey, workerTasksKey,
)
if err != nil {
b.Logger.Error().Stack().Err(err).Str("redis cmd", fmt.Sprintf("MULTI; RPOP %s; SADD %s %s; Set %s <marshaled> -1; EXEC", workerPendingQueueKey, workerTasksKey, t.UID, b.taskKey(queue.UID.String(), t.UID))).Msg("debug-next-task")
return nil, err
}
return t, nil
Expand Down