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:
parent
118ef27bf2
commit
d6f389e63f
@ -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.
|
// Stats represents a state of queues at a certain time.
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
// Name of the queue.
|
// Name of the queue.
|
||||||
|
@ -17,6 +17,41 @@ import (
|
|||||||
"github.com/hibiken/asynq/internal/base"
|
"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) {
|
func TestInspectorCurrentStats(t *testing.T) {
|
||||||
r := setup(t)
|
r := setup(t)
|
||||||
m1 := asynqtest.NewTaskMessage("task1", nil)
|
m1 := asynqtest.NewTaskMessage("task1", nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user