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

Rename Inspector.CurrentStats to GetQueueInfo

This commit is contained in:
Ken Hibino 2021-05-22 12:13:19 -07:00
parent 8ee1825e67
commit b358de907e
2 changed files with 12 additions and 12 deletions

View File

@ -44,8 +44,8 @@ func (i *Inspector) Queues() ([]string, error) {
return i.rdb.AllQueues() return i.rdb.AllQueues()
} }
// QueueStats represents a state of queues at a certain time. // QueueInfo represents a state of queues at a certain time.
type QueueStats struct { type QueueInfo struct {
// Name of the queue. // Name of the queue.
Queue string Queue string
// Total number of bytes that the queue and its tasks require to be stored in redis. // Total number of bytes that the queue and its tasks require to be stored in redis.
@ -75,8 +75,8 @@ type QueueStats struct {
Timestamp time.Time Timestamp time.Time
} }
// CurrentStats returns a current stats of the given queue. // GetQueueInfo returns current information of the given queue.
func (i *Inspector) CurrentStats(qname string) (*QueueStats, error) { func (i *Inspector) GetQueueInfo(qname string) (*QueueInfo, error) {
if err := base.ValidateQueueName(qname); err != nil { if err := base.ValidateQueueName(qname); err != nil {
return nil, err return nil, err
} }
@ -84,7 +84,7 @@ func (i *Inspector) CurrentStats(qname string) (*QueueStats, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &QueueStats{ return &QueueInfo{
Queue: stats.Queue, Queue: stats.Queue,
MemoryUsage: stats.MemoryUsage, MemoryUsage: stats.MemoryUsage,
Size: stats.Size, Size: stats.Size,

View File

@ -254,7 +254,7 @@ func TestInspectorDeleteQueueErrorQueueNotFound(t *testing.T) {
} }
} }
func TestInspectorCurrentStats(t *testing.T) { func TestInspectorGetQueueInfo(t *testing.T) {
r := setup(t) r := setup(t)
defer r.Close() defer r.Close()
m1 := h.NewTaskMessage("task1", nil) m1 := h.NewTaskMessage("task1", nil)
@ -265,7 +265,7 @@ func TestInspectorCurrentStats(t *testing.T) {
m6 := h.NewTaskMessageWithQueue("task6", nil, "low") m6 := h.NewTaskMessageWithQueue("task6", nil, "low")
now := time.Now() now := time.Now()
timeCmpOpt := cmpopts.EquateApproxTime(time.Second) timeCmpOpt := cmpopts.EquateApproxTime(time.Second)
ignoreMemUsg := cmpopts.IgnoreFields(QueueStats{}, "MemoryUsage") ignoreMemUsg := cmpopts.IgnoreFields(QueueInfo{}, "MemoryUsage")
inspector := NewInspector(getRedisConnOpt(t)) inspector := NewInspector(getRedisConnOpt(t))
@ -278,7 +278,7 @@ func TestInspectorCurrentStats(t *testing.T) {
processed map[string]int processed map[string]int
failed map[string]int failed map[string]int
qname string qname string
want *QueueStats want *QueueInfo
}{ }{
{ {
pending: map[string][]*base.TaskMessage{ pending: map[string][]*base.TaskMessage{
@ -320,7 +320,7 @@ func TestInspectorCurrentStats(t *testing.T) {
"low": 5, "low": 5,
}, },
qname: "default", qname: "default",
want: &QueueStats{ want: &QueueInfo{
Queue: "default", Queue: "default",
Size: 4, Size: 4,
Pending: 1, Pending: 1,
@ -352,14 +352,14 @@ func TestInspectorCurrentStats(t *testing.T) {
r.Set(failedKey, n, 0) r.Set(failedKey, n, 0)
} }
got, err := inspector.CurrentStats(tc.qname) got, err := inspector.GetQueueInfo(tc.qname)
if err != nil { if err != nil {
t.Errorf("r.CurrentStats(%q) = %v, %v, want %v, nil", t.Errorf("r.GetQueueInfo(%q) = %v, %v, want %v, nil",
tc.qname, got, err, tc.want) tc.qname, got, err, tc.want)
continue continue
} }
if diff := cmp.Diff(tc.want, got, timeCmpOpt, ignoreMemUsg); diff != "" { if diff := cmp.Diff(tc.want, got, timeCmpOpt, ignoreMemUsg); diff != "" {
t.Errorf("r.CurrentStats(%q) = %v, %v, want %v, nil; (-want, +got)\n%s", t.Errorf("r.GetQueueInfo(%q) = %v, %v, want %v, nil; (-want, +got)\n%s",
tc.qname, got, err, tc.want, diff) tc.qname, got, err, tc.want, diff)
continue continue
} }