2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-08-19 15:08:55 +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

@@ -345,11 +345,11 @@ func (r *RDB) listZSetEntries(key string, pgn Pagination) ([]base.Z, error) {
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.
//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 {
n, err := r.removeAndEnqueue(base.DeadKey(qname), base.QueueKey(qname), id.String(), float64(score))
func (r *RDB) RunDeadTask(qname string, id uuid.UUID, score int64) error {
n, err := r.removeAndRun(base.DeadKey(qname), base.QueueKey(qname), id.String(), float64(score))
if err != nil {
return err
}
@@ -359,11 +359,11 @@ func (r *RDB) EnqueueDeadTask(qname string, id uuid.UUID, score int64) error {
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.
// 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 {
n, err := r.removeAndEnqueue(base.RetryKey(qname), base.QueueKey(qname), id.String(), float64(score))
func (r *RDB) RunRetryTask(qname string, id uuid.UUID, score int64) error {
n, err := r.removeAndRun(base.RetryKey(qname), base.QueueKey(qname), id.String(), float64(score))
if err != nil {
return err
}
@@ -373,11 +373,11 @@ func (r *RDB) EnqueueRetryTask(qname string, id uuid.UUID, score int64) error {
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.
// 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 {
n, err := r.removeAndEnqueue(base.ScheduledKey(qname), base.QueueKey(qname), id.String(), float64(score))
func (r *RDB) RunScheduledTask(qname string, id uuid.UUID, score int64) error {
n, err := r.removeAndRun(base.ScheduledKey(qname), base.QueueKey(qname), id.String(), float64(score))
if err != nil {
return err
}
@@ -387,25 +387,25 @@ func (r *RDB) EnqueueScheduledTask(qname string, id uuid.UUID, score int64) erro
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.
func (r *RDB) EnqueueAllScheduledTasks(qname string) (int64, error) {
return r.removeAndEnqueueAll(base.ScheduledKey(qname), base.QueueKey(qname))
func (r *RDB) RunAllScheduledTasks(qname string) (int64, error) {
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.
func (r *RDB) EnqueueAllRetryTasks(qname string) (int64, error) {
return r.removeAndEnqueueAll(base.RetryKey(qname), base.QueueKey(qname))
func (r *RDB) RunAllRetryTasks(qname string) (int64, error) {
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.
func (r *RDB) EnqueueAllDeadTasks(qname string) (int64, error) {
return r.removeAndEnqueueAll(base.DeadKey(qname), base.QueueKey(qname))
func (r *RDB) RunAllDeadTasks(qname string) (int64, error) {
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])
for _, msg in ipairs(msgs) do
local decoded = cjson.decode(msg)
@@ -417,8 +417,8 @@ for _, msg in ipairs(msgs) do
end
return 0`)
func (r *RDB) removeAndEnqueue(zset, qkey, id string, score float64) (int64, error) {
res, err := removeAndEnqueueCmd.Run(r.client, []string{zset, qkey}, score, id).Result()
func (r *RDB) removeAndRun(zset, qkey, id string, score float64) (int64, error) {
res, err := removeAndRunCmd.Run(r.client, []string{zset, qkey}, score, id).Result()
if err != nil {
return 0, err
}
@@ -429,7 +429,7 @@ func (r *RDB) removeAndEnqueue(zset, qkey, id string, score float64) (int64, err
return n, nil
}
var removeAndEnqueueAllCmd = redis.NewScript(`
var removeAndRunAllCmd = redis.NewScript(`
local msgs = redis.call("ZRANGE", KEYS[1], 0, -1)
for _, msg in ipairs(msgs) do
redis.call("LPUSH", KEYS[2], msg)
@@ -437,8 +437,8 @@ for _, msg in ipairs(msgs) do
end
return table.getn(msgs)`)
func (r *RDB) removeAndEnqueueAll(zset, qkey string) (int64, error) {
res, err := removeAndEnqueueAllCmd.Run(r.client, []string{zset, qkey}).Result()
func (r *RDB) removeAndRunAll(zset, qkey string) (int64, error) {
res, err := removeAndRunAllCmd.Run(r.client, []string{zset, qkey}).Result()
if err != nil {
return 0, err
}

View File

@@ -981,7 +981,7 @@ var (
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)
t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil)
@@ -994,7 +994,7 @@ func TestEnqueueDeadTask(t *testing.T) {
qname string
score int64
id uuid.UUID
want error // expected return value from calling EnqueueDeadTask
want error // expected return value from calling RunDeadTask
wantDead 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.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 {
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
}
@@ -1085,7 +1085,7 @@ func TestEnqueueDeadTask(t *testing.T) {
}
}
func TestEnqueueRetryTask(t *testing.T) {
func TestRunRetryTask(t *testing.T) {
r := setup(t)
t1 := h.NewTaskMessage("send_email", nil)
@@ -1098,7 +1098,7 @@ func TestEnqueueRetryTask(t *testing.T) {
qname string
score int64
id uuid.UUID
want error // expected return value from calling EnqueueRetryTask
want error // expected return value from calling RunRetryTask
wantRetry 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.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 {
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
}
@@ -1189,7 +1189,7 @@ func TestEnqueueRetryTask(t *testing.T) {
}
}
func TestEnqueueScheduledTask(t *testing.T) {
func TestRunScheduledTask(t *testing.T) {
r := setup(t)
t1 := h.NewTaskMessage("send_email", nil)
t2 := h.NewTaskMessage("gen_thumbnail", nil)
@@ -1202,7 +1202,7 @@ func TestEnqueueScheduledTask(t *testing.T) {
qname string
score int64
id uuid.UUID
want error // expected return value from calling EnqueueScheduledTask
want error // expected return value from calling RunScheduledTask
wantScheduled 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.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 {
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
}
@@ -1293,7 +1293,7 @@ func TestEnqueueScheduledTask(t *testing.T) {
}
}
func TestEnqueueAllScheduledTasks(t *testing.T) {
func TestRunAllScheduledTasks(t *testing.T) {
r := setup(t)
t1 := h.NewTaskMessage("send_email", 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.SeedAllScheduledQueues(t, r.client, tc.scheduled)
got, err := r.EnqueueAllScheduledTasks(tc.qname)
got, err := r.RunAllScheduledTasks(tc.qname)
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)
continue
}
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)
}
@@ -1398,7 +1398,7 @@ func TestEnqueueAllScheduledTasks(t *testing.T) {
}
}
func TestEnqueueAllRetryTasks(t *testing.T) {
func TestRunAllRetryTasks(t *testing.T) {
r := setup(t)
t1 := h.NewTaskMessage("send_email", 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.SeedAllRetryQueues(t, r.client, tc.retry)
got, err := r.EnqueueAllRetryTasks(tc.qname)
got, err := r.RunAllRetryTasks(tc.qname)
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)
continue
}
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)
}
@@ -1503,7 +1503,7 @@ func TestEnqueueAllRetryTasks(t *testing.T) {
}
}
func TestEnqueueAllDeadTasks(t *testing.T) {
func TestRunAllDeadTasks(t *testing.T) {
r := setup(t)
t1 := h.NewTaskMessage("send_email", 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.SeedAllDeadQueues(t, r.client, tc.dead)
got, err := r.EnqueueAllDeadTasks(tc.qname)
got, err := r.RunAllDeadTasks(tc.qname)
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)
continue
}
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)
}