2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-11-10 11:31:58 +08:00

Rename Enqueue methods in Inspector to Run

This commit is contained in:
Ken Hibino 2020-09-05 13:35:52 -07:00
parent a891ce5568
commit 29e542e591
5 changed files with 93 additions and 94 deletions

View File

@ -171,17 +171,17 @@ type DeadTask struct {
score int64 score int64
} }
// Key returns a key used to delete, enqueue, and kill the task. // Key returns a key used to delete, run, and kill the task.
func (t *ScheduledTask) Key() string { func (t *ScheduledTask) Key() string {
return fmt.Sprintf("s:%v:%v", t.ID, t.score) return fmt.Sprintf("s:%v:%v", t.ID, t.score)
} }
// Key returns a key used to delete, enqueue, and kill the task. // Key returns a key used to delete, run, and kill the task.
func (t *RetryTask) Key() string { func (t *RetryTask) Key() string {
return fmt.Sprintf("r:%v:%v", t.ID, t.score) return fmt.Sprintf("r:%v:%v", t.ID, t.score)
} }
// Key returns a key used to delete, enqueue, and kill the task. // Key returns a key used to delete, run, and kill the task.
func (t *DeadTask) Key() string { func (t *DeadTask) Key() string {
return fmt.Sprintf("d:%v:%v", t.ID, t.score) return fmt.Sprintf("d:%v:%v", t.ID, t.score)
} }
@ -463,39 +463,38 @@ func (i *Inspector) DeleteTaskByKey(qname, key string) error {
} }
} }
// TODO(hibiken): Use different verb here. Idea: Run or Stage // RunAllScheduledTasks transition all scheduled tasks to pending state within the given queue,
// EnqueueAllScheduledTasks enqueues all scheduled tasks for immediate processing within the given queue, // and reports the number of tasks transitioned.
// and reports the number of tasks enqueued. func (i *Inspector) RunAllScheduledTasks(qname string) (int, error) {
func (i *Inspector) EnqueueAllScheduledTasks(qname string) (int, error) {
if err := validateQueueName(qname); err != nil { if err := validateQueueName(qname); err != nil {
return 0, err return 0, err
} }
n, err := i.rdb.EnqueueAllScheduledTasks(qname) n, err := i.rdb.RunAllScheduledTasks(qname)
return int(n), err return int(n), err
} }
// EnqueueAllRetryTasks enqueues all retry tasks for immediate processing within the given queue, // RunAllRetryTasks transition all retry tasks to pending state within the given queue,
// and reports the number of tasks enqueued. // and reports the number of tasks transitioned.
func (i *Inspector) EnqueueAllRetryTasks(qname string) (int, error) { func (i *Inspector) RunAllRetryTasks(qname string) (int, error) {
if err := validateQueueName(qname); err != nil { if err := validateQueueName(qname); err != nil {
return 0, err return 0, err
} }
n, err := i.rdb.EnqueueAllRetryTasks(qname) n, err := i.rdb.RunAllRetryTasks(qname)
return int(n), err return int(n), err
} }
// EnqueueAllDeadTasks enqueues all dead tasks for immediate processing within the given queue, // RunAllDeadTasks transition all dead tasks to pending state within the given queue,
// and reports the number of tasks enqueued. // and reports the number of tasks transitioned.
func (i *Inspector) EnqueueAllDeadTasks(qname string) (int, error) { func (i *Inspector) RunAllDeadTasks(qname string) (int, error) {
if err := validateQueueName(qname); err != nil { if err := validateQueueName(qname); err != nil {
return 0, err return 0, err
} }
n, err := i.rdb.EnqueueAllDeadTasks(qname) n, err := i.rdb.RunAllDeadTasks(qname)
return int(n), err return int(n), err
} }
// EnqueueTaskByKey enqueues a task with the given key in the given queue. // RunTaskByKey transition a task to pending state given task key and queue name.
func (i *Inspector) EnqueueTaskByKey(qname, key string) error { func (i *Inspector) RunTaskByKey(qname, key string) error {
if err := validateQueueName(qname); err != nil { if err := validateQueueName(qname); err != nil {
return err return err
} }
@ -505,11 +504,11 @@ func (i *Inspector) EnqueueTaskByKey(qname, key string) error {
} }
switch state { switch state {
case "s": case "s":
return i.rdb.EnqueueScheduledTask(qname, id, score) return i.rdb.RunScheduledTask(qname, id, score)
case "r": case "r":
return i.rdb.EnqueueRetryTask(qname, id, score) return i.rdb.RunRetryTask(qname, id, score)
case "d": case "d":
return i.rdb.EnqueueDeadTask(qname, id, score) return i.rdb.RunDeadTask(qname, id, score)
default: default:
return fmt.Errorf("invalid key") return fmt.Errorf("invalid key")
} }

View File

@ -1068,7 +1068,7 @@ func TestInspectorKillAllRetryTasks(t *testing.T) {
} }
} }
func TestInspectorEnqueueAllScheduledTasks(t *testing.T) { func TestInspectorRunAllScheduledTasks(t *testing.T) {
r := setup(t) r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil) m1 := asynqtest.NewTaskMessage("task1", nil)
m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical") m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical")
@ -1161,13 +1161,13 @@ func TestInspectorEnqueueAllScheduledTasks(t *testing.T) {
asynqtest.SeedAllScheduledQueues(t, r, tc.scheduled) asynqtest.SeedAllScheduledQueues(t, r, tc.scheduled)
asynqtest.SeedAllPendingQueues(t, r, tc.pending) asynqtest.SeedAllPendingQueues(t, r, tc.pending)
got, err := inspector.EnqueueAllScheduledTasks(tc.qname) got, err := inspector.RunAllScheduledTasks(tc.qname)
if err != nil { if err != nil {
t.Errorf("EnqueueAllScheduledTasks(%q) returned error: %v", tc.qname, err) t.Errorf("RunAllScheduledTasks(%q) returned error: %v", tc.qname, err)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("EnqueueAllScheduledTasks(%q) = %d, want %d", tc.qname, got, tc.want) t.Errorf("RunAllScheduledTasks(%q) = %d, want %d", tc.qname, got, tc.want)
} }
for qname, want := range tc.wantScheduled { for qname, want := range tc.wantScheduled {
gotScheduled := asynqtest.GetScheduledEntries(t, r, qname) gotScheduled := asynqtest.GetScheduledEntries(t, r, qname)
@ -1184,7 +1184,7 @@ func TestInspectorEnqueueAllScheduledTasks(t *testing.T) {
} }
} }
func TestInspectorEnqueueAllRetryTasks(t *testing.T) { func TestInspectorRunAllRetryTasks(t *testing.T) {
r := setup(t) r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil) m1 := asynqtest.NewTaskMessage("task1", nil)
m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical") m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical")
@ -1277,13 +1277,13 @@ func TestInspectorEnqueueAllRetryTasks(t *testing.T) {
asynqtest.SeedAllRetryQueues(t, r, tc.retry) asynqtest.SeedAllRetryQueues(t, r, tc.retry)
asynqtest.SeedAllPendingQueues(t, r, tc.pending) asynqtest.SeedAllPendingQueues(t, r, tc.pending)
got, err := inspector.EnqueueAllRetryTasks(tc.qname) got, err := inspector.RunAllRetryTasks(tc.qname)
if err != nil { if err != nil {
t.Errorf("EnqueueAllRetryTasks(%q) returned error: %v", tc.qname, err) t.Errorf("RunAllRetryTasks(%q) returned error: %v", tc.qname, err)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("EnqueueAllRetryTasks(%q) = %d, want %d", tc.qname, got, tc.want) t.Errorf("RunAllRetryTasks(%q) = %d, want %d", tc.qname, got, tc.want)
} }
for qname, want := range tc.wantRetry { for qname, want := range tc.wantRetry {
gotRetry := asynqtest.GetRetryEntries(t, r, qname) gotRetry := asynqtest.GetRetryEntries(t, r, qname)
@ -1300,7 +1300,7 @@ func TestInspectorEnqueueAllRetryTasks(t *testing.T) {
} }
} }
func TestInspectorEnqueueAllDeadTasks(t *testing.T) { func TestInspectorRunAllDeadTasks(t *testing.T) {
r := setup(t) r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil) m1 := asynqtest.NewTaskMessage("task1", nil)
m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical") m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical")
@ -1389,13 +1389,13 @@ func TestInspectorEnqueueAllDeadTasks(t *testing.T) {
asynqtest.SeedAllDeadQueues(t, r, tc.dead) asynqtest.SeedAllDeadQueues(t, r, tc.dead)
asynqtest.SeedAllPendingQueues(t, r, tc.pending) asynqtest.SeedAllPendingQueues(t, r, tc.pending)
got, err := inspector.EnqueueAllDeadTasks(tc.qname) got, err := inspector.RunAllDeadTasks(tc.qname)
if err != nil { if err != nil {
t.Errorf("EnqueueAllDeadTasks(%q) returned error: %v", tc.qname, err) t.Errorf("RunAllDeadTasks(%q) returned error: %v", tc.qname, err)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("EnqueueAllDeadTasks(%q) = %d, want %d", tc.qname, got, tc.want) t.Errorf("RunAllDeadTasks(%q) = %d, want %d", tc.qname, got, tc.want)
} }
for qname, want := range tc.wantDead { for qname, want := range tc.wantDead {
gotDead := asynqtest.GetDeadEntries(t, r, qname) gotDead := asynqtest.GetDeadEntries(t, r, qname)
@ -1560,7 +1560,7 @@ func TestInspectorDeleteTaskByKeyDeletesDeadTask(t *testing.T) {
} }
} }
func TestInspectorEnqueueTaskByKeyEnqueuesScheduledTask(t *testing.T) { func TestInspectorRunTaskByKeyRunsScheduledTask(t *testing.T) {
r := setup(t) r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil) m1 := asynqtest.NewTaskMessage("task1", nil)
m2 := asynqtest.NewTaskMessage("task2", nil) m2 := asynqtest.NewTaskMessage("task2", nil)
@ -1607,8 +1607,8 @@ func TestInspectorEnqueueTaskByKeyEnqueuesScheduledTask(t *testing.T) {
asynqtest.SeedAllScheduledQueues(t, r, tc.scheduled) asynqtest.SeedAllScheduledQueues(t, r, tc.scheduled)
asynqtest.SeedAllPendingQueues(t, r, tc.pending) asynqtest.SeedAllPendingQueues(t, r, tc.pending)
if err := inspector.EnqueueTaskByKey(tc.qname, tc.key); err != nil { if err := inspector.RunTaskByKey(tc.qname, tc.key); err != nil {
t.Errorf("EnqueueTaskByKey(%q, %q) returned error: %v", tc.qname, tc.key, err) t.Errorf("RunTaskByKey(%q, %q) returned error: %v", tc.qname, tc.key, err)
continue continue
} }
for qname, want := range tc.wantScheduled { for qname, want := range tc.wantScheduled {
@ -1629,7 +1629,7 @@ func TestInspectorEnqueueTaskByKeyEnqueuesScheduledTask(t *testing.T) {
} }
} }
func TestInspectorEnqueueTaskByKeyEnqueuesRetryTask(t *testing.T) { func TestInspectorRunTaskByKeyRunsRetryTask(t *testing.T) {
r := setup(t) r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil) m1 := asynqtest.NewTaskMessage("task1", nil)
m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "custom") m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "custom")
@ -1676,8 +1676,8 @@ func TestInspectorEnqueueTaskByKeyEnqueuesRetryTask(t *testing.T) {
asynqtest.SeedAllRetryQueues(t, r, tc.retry) asynqtest.SeedAllRetryQueues(t, r, tc.retry)
asynqtest.SeedAllPendingQueues(t, r, tc.pending) asynqtest.SeedAllPendingQueues(t, r, tc.pending)
if err := inspector.EnqueueTaskByKey(tc.qname, tc.key); err != nil { if err := inspector.RunTaskByKey(tc.qname, tc.key); err != nil {
t.Errorf("EnqueueTaskByKey(%q, %q) returned error: %v", tc.qname, tc.key, err) t.Errorf("RunTaskByKey(%q, %q) returned error: %v", tc.qname, tc.key, err)
continue continue
} }
for qname, want := range tc.wantRetry { for qname, want := range tc.wantRetry {
@ -1697,7 +1697,7 @@ func TestInspectorEnqueueTaskByKeyEnqueuesRetryTask(t *testing.T) {
} }
} }
func TestInspectorEnqueueTaskByKeyEnqueuesDeadTask(t *testing.T) { func TestInspectorRunTaskByKeyRunsDeadTask(t *testing.T) {
r := setup(t) r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil) m1 := asynqtest.NewTaskMessage("task1", nil)
m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical") m2 := asynqtest.NewTaskMessageWithQueue("task2", nil, "critical")
@ -1748,8 +1748,8 @@ func TestInspectorEnqueueTaskByKeyEnqueuesDeadTask(t *testing.T) {
asynqtest.SeedAllDeadQueues(t, r, tc.dead) asynqtest.SeedAllDeadQueues(t, r, tc.dead)
asynqtest.SeedAllPendingQueues(t, r, tc.pending) asynqtest.SeedAllPendingQueues(t, r, tc.pending)
if err := inspector.EnqueueTaskByKey(tc.qname, tc.key); err != nil { if err := inspector.RunTaskByKey(tc.qname, tc.key); err != nil {
t.Errorf("EnqueueTaskByKey(%q, %q) returned error: %v", tc.qname, tc.key, err) t.Errorf("RunTaskByKey(%q, %q) returned error: %v", tc.qname, tc.key, err)
continue continue
} }
for qname, want := range tc.wantDead { for qname, want := range tc.wantDead {

View File

@ -345,11 +345,11 @@ func (r *RDB) listZSetEntries(key string, pgn Pagination) ([]base.Z, error) {
return res, nil return res, nil
} }
// EnqueueDeadTask finds a dead task that matches the given id and score from // RunDeadTask finds a dead task that matches the given id and score from
// the given queue and enqueues it for processing. // the given queue and enqueues it for processing.
//If a task that matches the id and score does not exist, it returns ErrTaskNotFound. //If a task that matches the id and score does not exist, it returns ErrTaskNotFound.
func (r *RDB) EnqueueDeadTask(qname string, id uuid.UUID, score int64) error { func (r *RDB) RunDeadTask(qname string, id uuid.UUID, score int64) error {
n, err := r.removeAndEnqueue(base.DeadKey(qname), base.QueueKey(qname), id.String(), float64(score)) n, err := r.removeAndRun(base.DeadKey(qname), base.QueueKey(qname), id.String(), float64(score))
if err != nil { if err != nil {
return err return err
} }
@ -359,11 +359,11 @@ func (r *RDB) EnqueueDeadTask(qname string, id uuid.UUID, score int64) error {
return nil return nil
} }
// EnqueueRetryTask finds a retry task that matches the given id and score from // RunRetryTask finds a retry task that matches the given id and score from
// the given queue and enqueues it for processing. // the given queue and enqueues it for processing.
// If a task that matches the id and score does not exist, it returns ErrTaskNotFound. // If a task that matches the id and score does not exist, it returns ErrTaskNotFound.
func (r *RDB) EnqueueRetryTask(qname string, id uuid.UUID, score int64) error { func (r *RDB) RunRetryTask(qname string, id uuid.UUID, score int64) error {
n, err := r.removeAndEnqueue(base.RetryKey(qname), base.QueueKey(qname), id.String(), float64(score)) n, err := r.removeAndRun(base.RetryKey(qname), base.QueueKey(qname), id.String(), float64(score))
if err != nil { if err != nil {
return err return err
} }
@ -373,11 +373,11 @@ func (r *RDB) EnqueueRetryTask(qname string, id uuid.UUID, score int64) error {
return nil return nil
} }
// EnqueueScheduledTask finds a scheduled task that matches the given id and score from // RunScheduledTask finds a scheduled task that matches the given id and score from
// from the given queue and enqueues it for processing. // from the given queue and enqueues it for processing.
// If a task that matches the id and score does not exist, it returns ErrTaskNotFound. // If a task that matches the id and score does not exist, it returns ErrTaskNotFound.
func (r *RDB) EnqueueScheduledTask(qname string, id uuid.UUID, score int64) error { func (r *RDB) RunScheduledTask(qname string, id uuid.UUID, score int64) error {
n, err := r.removeAndEnqueue(base.ScheduledKey(qname), base.QueueKey(qname), id.String(), float64(score)) n, err := r.removeAndRun(base.ScheduledKey(qname), base.QueueKey(qname), id.String(), float64(score))
if err != nil { if err != nil {
return err return err
} }
@ -387,25 +387,25 @@ func (r *RDB) EnqueueScheduledTask(qname string, id uuid.UUID, score int64) erro
return nil return nil
} }
// EnqueueAllScheduledTasks enqueues all scheduled tasks from the given queue // RunAllScheduledTasks enqueues all scheduled tasks from the given queue
// and returns the number of tasks enqueued. // and returns the number of tasks enqueued.
func (r *RDB) EnqueueAllScheduledTasks(qname string) (int64, error) { func (r *RDB) RunAllScheduledTasks(qname string) (int64, error) {
return r.removeAndEnqueueAll(base.ScheduledKey(qname), base.QueueKey(qname)) return r.removeAndRunAll(base.ScheduledKey(qname), base.QueueKey(qname))
} }
// EnqueueAllRetryTasks enqueues all retry tasks from the given queue // RunAllRetryTasks enqueues all retry tasks from the given queue
// and returns the number of tasks enqueued. // and returns the number of tasks enqueued.
func (r *RDB) EnqueueAllRetryTasks(qname string) (int64, error) { func (r *RDB) RunAllRetryTasks(qname string) (int64, error) {
return r.removeAndEnqueueAll(base.RetryKey(qname), base.QueueKey(qname)) return r.removeAndRunAll(base.RetryKey(qname), base.QueueKey(qname))
} }
// EnqueueAllDeadTasks enqueues all tasks from dead queue // RunAllDeadTasks enqueues all tasks from dead queue
// and returns the number of tasks enqueued. // and returns the number of tasks enqueued.
func (r *RDB) EnqueueAllDeadTasks(qname string) (int64, error) { func (r *RDB) RunAllDeadTasks(qname string) (int64, error) {
return r.removeAndEnqueueAll(base.DeadKey(qname), base.QueueKey(qname)) return r.removeAndRunAll(base.DeadKey(qname), base.QueueKey(qname))
} }
var removeAndEnqueueCmd = redis.NewScript(` var removeAndRunCmd = redis.NewScript(`
local msgs = redis.call("ZRANGEBYSCORE", KEYS[1], ARGV[1], ARGV[1]) local msgs = redis.call("ZRANGEBYSCORE", KEYS[1], ARGV[1], ARGV[1])
for _, msg in ipairs(msgs) do for _, msg in ipairs(msgs) do
local decoded = cjson.decode(msg) local decoded = cjson.decode(msg)
@ -417,8 +417,8 @@ for _, msg in ipairs(msgs) do
end end
return 0`) return 0`)
func (r *RDB) removeAndEnqueue(zset, qkey, id string, score float64) (int64, error) { func (r *RDB) removeAndRun(zset, qkey, id string, score float64) (int64, error) {
res, err := removeAndEnqueueCmd.Run(r.client, []string{zset, qkey}, score, id).Result() res, err := removeAndRunCmd.Run(r.client, []string{zset, qkey}, score, id).Result()
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -429,7 +429,7 @@ func (r *RDB) removeAndEnqueue(zset, qkey, id string, score float64) (int64, err
return n, nil return n, nil
} }
var removeAndEnqueueAllCmd = redis.NewScript(` var removeAndRunAllCmd = redis.NewScript(`
local msgs = redis.call("ZRANGE", KEYS[1], 0, -1) local msgs = redis.call("ZRANGE", KEYS[1], 0, -1)
for _, msg in ipairs(msgs) do for _, msg in ipairs(msgs) do
redis.call("LPUSH", KEYS[2], msg) redis.call("LPUSH", KEYS[2], msg)
@ -437,8 +437,8 @@ for _, msg in ipairs(msgs) do
end end
return table.getn(msgs)`) return table.getn(msgs)`)
func (r *RDB) removeAndEnqueueAll(zset, qkey string) (int64, error) { func (r *RDB) removeAndRunAll(zset, qkey string) (int64, error) {
res, err := removeAndEnqueueAllCmd.Run(r.client, []string{zset, qkey}).Result() res, err := removeAndRunAllCmd.Run(r.client, []string{zset, qkey}).Result()
if err != nil { if err != nil {
return 0, err return 0, err
} }

View File

@ -981,7 +981,7 @@ var (
zScoreCmpOpt = h.EquateInt64Approx(2) // allow for 2 seconds margin in Z.Score zScoreCmpOpt = h.EquateInt64Approx(2) // allow for 2 seconds margin in Z.Score
) )
func TestEnqueueDeadTask(t *testing.T) { func TestRunDeadTask(t *testing.T) {
r := setup(t) r := setup(t)
t1 := h.NewTaskMessage("send_email", nil) t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil) t2 := h.NewTaskMessage("gen_thumbnail", nil)
@ -994,7 +994,7 @@ func TestEnqueueDeadTask(t *testing.T) {
qname string qname string
score int64 score int64
id uuid.UUID id uuid.UUID
want error // expected return value from calling EnqueueDeadTask want error // expected return value from calling RunDeadTask
wantDead map[string][]*base.TaskMessage wantDead map[string][]*base.TaskMessage
wantPending map[string][]*base.TaskMessage wantPending map[string][]*base.TaskMessage
}{ }{
@ -1063,9 +1063,9 @@ func TestEnqueueDeadTask(t *testing.T) {
h.FlushDB(t, r.client) // clean up db before each test case h.FlushDB(t, r.client) // clean up db before each test case
h.SeedAllDeadQueues(t, r.client, tc.dead) h.SeedAllDeadQueues(t, r.client, tc.dead)
got := r.EnqueueDeadTask(tc.qname, tc.id, tc.score) got := r.RunDeadTask(tc.qname, tc.id, tc.score)
if got != tc.want { if got != tc.want {
t.Errorf("r.EnqueueDeadTask(%q, %s, %d) = %v, want %v", tc.qname, tc.id, tc.score, got, tc.want) t.Errorf("r.RunDeadTask(%q, %s, %d) = %v, want %v", tc.qname, tc.id, tc.score, got, tc.want)
continue continue
} }
@ -1085,7 +1085,7 @@ func TestEnqueueDeadTask(t *testing.T) {
} }
} }
func TestEnqueueRetryTask(t *testing.T) { func TestRunRetryTask(t *testing.T) {
r := setup(t) r := setup(t)
t1 := h.NewTaskMessage("send_email", nil) t1 := h.NewTaskMessage("send_email", nil)
@ -1098,7 +1098,7 @@ func TestEnqueueRetryTask(t *testing.T) {
qname string qname string
score int64 score int64
id uuid.UUID id uuid.UUID
want error // expected return value from calling EnqueueRetryTask want error // expected return value from calling RunRetryTask
wantRetry map[string][]*base.TaskMessage wantRetry map[string][]*base.TaskMessage
wantPending map[string][]*base.TaskMessage wantPending map[string][]*base.TaskMessage
}{ }{
@ -1167,9 +1167,9 @@ func TestEnqueueRetryTask(t *testing.T) {
h.FlushDB(t, r.client) // clean up db before each test case h.FlushDB(t, r.client) // clean up db before each test case
h.SeedAllRetryQueues(t, r.client, tc.retry) // initialize retry queue h.SeedAllRetryQueues(t, r.client, tc.retry) // initialize retry queue
got := r.EnqueueRetryTask(tc.qname, tc.id, tc.score) got := r.RunRetryTask(tc.qname, tc.id, tc.score)
if got != tc.want { if got != tc.want {
t.Errorf("r.EnqueueRetryTask(%q, %s, %d) = %v, want %v", tc.qname, tc.id, tc.score, got, tc.want) t.Errorf("r.RunRetryTask(%q, %s, %d) = %v, want %v", tc.qname, tc.id, tc.score, got, tc.want)
continue continue
} }
@ -1189,7 +1189,7 @@ func TestEnqueueRetryTask(t *testing.T) {
} }
} }
func TestEnqueueScheduledTask(t *testing.T) { func TestRunScheduledTask(t *testing.T) {
r := setup(t) r := setup(t)
t1 := h.NewTaskMessage("send_email", nil) t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil) t2 := h.NewTaskMessage("gen_thumbnail", nil)
@ -1202,7 +1202,7 @@ func TestEnqueueScheduledTask(t *testing.T) {
qname string qname string
score int64 score int64
id uuid.UUID id uuid.UUID
want error // expected return value from calling EnqueueScheduledTask want error // expected return value from calling RunScheduledTask
wantScheduled map[string][]*base.TaskMessage wantScheduled map[string][]*base.TaskMessage
wantPending map[string][]*base.TaskMessage wantPending map[string][]*base.TaskMessage
}{ }{
@ -1271,9 +1271,9 @@ func TestEnqueueScheduledTask(t *testing.T) {
h.FlushDB(t, r.client) // clean up db before each test case h.FlushDB(t, r.client) // clean up db before each test case
h.SeedAllScheduledQueues(t, r.client, tc.scheduled) h.SeedAllScheduledQueues(t, r.client, tc.scheduled)
got := r.EnqueueScheduledTask(tc.qname, tc.id, tc.score) got := r.RunScheduledTask(tc.qname, tc.id, tc.score)
if got != tc.want { if got != tc.want {
t.Errorf("r.EnqueueRetryTask(%q, %s, %d) = %v, want %v", tc.qname, tc.id, tc.score, got, tc.want) t.Errorf("r.RunRetryTask(%q, %s, %d) = %v, want %v", tc.qname, tc.id, tc.score, got, tc.want)
continue continue
} }
@ -1293,7 +1293,7 @@ func TestEnqueueScheduledTask(t *testing.T) {
} }
} }
func TestEnqueueAllScheduledTasks(t *testing.T) { func TestRunAllScheduledTasks(t *testing.T) {
r := setup(t) r := setup(t)
t1 := h.NewTaskMessage("send_email", nil) t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil) t2 := h.NewTaskMessage("gen_thumbnail", nil)
@ -1371,15 +1371,15 @@ func TestEnqueueAllScheduledTasks(t *testing.T) {
h.FlushDB(t, r.client) // clean up db before each test case h.FlushDB(t, r.client) // clean up db before each test case
h.SeedAllScheduledQueues(t, r.client, tc.scheduled) h.SeedAllScheduledQueues(t, r.client, tc.scheduled)
got, err := r.EnqueueAllScheduledTasks(tc.qname) got, err := r.RunAllScheduledTasks(tc.qname)
if err != nil { if err != nil {
t.Errorf("%s; r.EnqueueAllScheduledTasks(%q) = %v, %v; want %v, nil", t.Errorf("%s; r.RunAllScheduledTasks(%q) = %v, %v; want %v, nil",
tc.desc, tc.qname, got, err, tc.want) tc.desc, tc.qname, got, err, tc.want)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("%s; r.EnqueueAllScheduledTasks(%q) = %v, %v; want %v, nil", t.Errorf("%s; r.RunAllScheduledTasks(%q) = %v, %v; want %v, nil",
tc.desc, tc.qname, got, err, tc.want) tc.desc, tc.qname, got, err, tc.want)
} }
@ -1398,7 +1398,7 @@ func TestEnqueueAllScheduledTasks(t *testing.T) {
} }
} }
func TestEnqueueAllRetryTasks(t *testing.T) { func TestRunAllRetryTasks(t *testing.T) {
r := setup(t) r := setup(t)
t1 := h.NewTaskMessage("send_email", nil) t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil) t2 := h.NewTaskMessage("gen_thumbnail", nil)
@ -1476,15 +1476,15 @@ func TestEnqueueAllRetryTasks(t *testing.T) {
h.FlushDB(t, r.client) // clean up db before each test case h.FlushDB(t, r.client) // clean up db before each test case
h.SeedAllRetryQueues(t, r.client, tc.retry) h.SeedAllRetryQueues(t, r.client, tc.retry)
got, err := r.EnqueueAllRetryTasks(tc.qname) got, err := r.RunAllRetryTasks(tc.qname)
if err != nil { if err != nil {
t.Errorf("%s; r.EnqueueAllRetryTasks(%q) = %v, %v; want %v, nil", t.Errorf("%s; r.RunAllRetryTasks(%q) = %v, %v; want %v, nil",
tc.desc, tc.qname, got, err, tc.want) tc.desc, tc.qname, got, err, tc.want)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("%s; r.EnqueueAllRetryTasks(%q) = %v, %v; want %v, nil", t.Errorf("%s; r.RunAllRetryTasks(%q) = %v, %v; want %v, nil",
tc.desc, tc.qname, got, err, tc.want) tc.desc, tc.qname, got, err, tc.want)
} }
@ -1503,7 +1503,7 @@ func TestEnqueueAllRetryTasks(t *testing.T) {
} }
} }
func TestEnqueueAllDeadTasks(t *testing.T) { func TestRunAllDeadTasks(t *testing.T) {
r := setup(t) r := setup(t)
t1 := h.NewTaskMessage("send_email", nil) t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil) t2 := h.NewTaskMessage("gen_thumbnail", nil)
@ -1581,15 +1581,15 @@ func TestEnqueueAllDeadTasks(t *testing.T) {
h.FlushDB(t, r.client) // clean up db before each test case h.FlushDB(t, r.client) // clean up db before each test case
h.SeedAllDeadQueues(t, r.client, tc.dead) h.SeedAllDeadQueues(t, r.client, tc.dead)
got, err := r.EnqueueAllDeadTasks(tc.qname) got, err := r.RunAllDeadTasks(tc.qname)
if err != nil { if err != nil {
t.Errorf("%s; r.EnqueueAllDeadTasks(%q) = %v, %v; want %v, nil", t.Errorf("%s; r.RunAllDeadTasks(%q) = %v, %v; want %v, nil",
tc.desc, tc.qname, got, err, tc.want) tc.desc, tc.qname, got, err, tc.want)
continue continue
} }
if got != tc.want { if got != tc.want {
t.Errorf("%s; r.EnqueueAllDeadTasks(%q) = %v, %v; want %v, nil", t.Errorf("%s; r.RunAllDeadTasks(%q) = %v, %v; want %v, nil",
tc.desc, tc.qname, got, err, tc.want) tc.desc, tc.qname, got, err, tc.want)
} }

View File

@ -360,7 +360,7 @@ func taskRun(cmd *cobra.Command, args []string) {
} }
i := createInspector() i := createInspector()
err = i.EnqueueTaskByKey(qname, key) err = i.RunTaskByKey(qname, key)
if err != nil { if err != nil {
fmt.Printf("error: %v\n", err) fmt.Printf("error: %v\n", err)
os.Exit(1) os.Exit(1)
@ -446,11 +446,11 @@ func taskRunAll(cmd *cobra.Command, args []string) {
var n int var n int
switch state { switch state {
case "scheduled": case "scheduled":
n, err = i.EnqueueAllScheduledTasks(qname) n, err = i.RunAllScheduledTasks(qname)
case "retry": case "retry":
n, err = i.EnqueueAllRetryTasks(qname) n, err = i.RunAllRetryTasks(qname)
case "dead": case "dead":
n, err = i.EnqueueAllDeadTasks(qname) n, err = i.RunAllDeadTasks(qname)
default: default:
fmt.Printf("error: unsupported state %q\n", state) fmt.Printf("error: unsupported state %q\n", state)
os.Exit(1) os.Exit(1)