2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-26 07:42:17 +08:00

Add Queues method to Inspector

This commit is contained in:
Ken Hibino 2020-08-20 21:17:44 -07:00
parent 118ef27bf2
commit d6f389e63f
2 changed files with 40 additions and 0 deletions

View File

@ -27,6 +27,11 @@ func NewInspector(r RedisConnOpt) *Inspector {
}
}
// Queues returns a list of all queue names.
func (i *Inspector) Queues() ([]string, error) {
return i.rdb.AllQueues()
}
// Stats represents a state of queues at a certain time.
type Stats struct {
// Name of the queue.

View File

@ -17,6 +17,41 @@ import (
"github.com/hibiken/asynq/internal/base"
)
func TestInspectorQueues(t *testing.T) {
r := setup(t)
inspector := NewInspector(RedisClientOpt{
Addr: redisAddr,
DB: redisDB,
})
tests := []struct {
queues []string
}{
{queues: []string{"default"}},
{queues: []string{"custom1", "custom2"}},
{queues: []string{"default", "custom1", "custom2"}},
{queues: []string{}},
}
for _, tc := range tests {
h.FlushDB(t, r)
for _, qname := range tc.queues {
if err := r.SAdd(base.AllQueues, qname).Err(); err != nil {
t.Fatalf("could not initialize all queue set: %v", err)
}
}
got, err := inspector.Queues()
if err != nil {
t.Errorf("Queues() returned an error: %v", err)
continue
}
if diff := cmp.Diff(tc.queues, got, h.SortStringSliceOpt); diff != "" {
t.Errorf("Queues() = %v, want %v; (-want, +got)\n%s", got, tc.queues, diff)
}
}
}
func TestInspectorCurrentStats(t *testing.T) {
r := setup(t)
m1 := asynqtest.NewTaskMessage("task1", nil)