mirror of
https://github.com/hibiken/asynq.git
synced 2024-11-10 11:31:58 +08:00
Update Inspector.ListArchivedTasks
This commit is contained in:
parent
cd351d49b9
commit
e63d51da0c
19
inspector.go
19
inspector.go
@ -455,7 +455,7 @@ func (i *Inspector) ListRetryTasks(qname string, opts ...ListOption) ([]*TaskInf
|
|||||||
// Tasks are sorted by LastFailedAt in descending order.
|
// Tasks are sorted by LastFailedAt in descending order.
|
||||||
//
|
//
|
||||||
// By default, it retrieves the first 30 tasks.
|
// By default, it retrieves the first 30 tasks.
|
||||||
func (i *Inspector) ListArchivedTasks(qname string, opts ...ListOption) ([]*ArchivedTask, error) {
|
func (i *Inspector) ListArchivedTasks(qname string, opts ...ListOption) ([]*TaskInfo, error) {
|
||||||
if err := base.ValidateQueueName(qname); err != nil {
|
if err := base.ValidateQueueName(qname); err != nil {
|
||||||
return nil, fmt.Errorf("asynq: %v", err)
|
return nil, fmt.Errorf("asynq: %v", err)
|
||||||
}
|
}
|
||||||
@ -466,20 +466,11 @@ func (i *Inspector) ListArchivedTasks(qname string, opts ...ListOption) ([]*Arch
|
|||||||
// TODO: handle ErrQueueNotFound
|
// TODO: handle ErrQueueNotFound
|
||||||
return nil, fmt.Errorf("asynq: %v", err)
|
return nil, fmt.Errorf("asynq: %v", err)
|
||||||
}
|
}
|
||||||
var tasks []*ArchivedTask
|
var tasks []*TaskInfo
|
||||||
for _, z := range zs {
|
for _, z := range zs {
|
||||||
failedAt := time.Unix(z.Score, 0)
|
tasks = append(tasks, &TaskInfo{
|
||||||
t := NewTask(z.Message.Type, z.Message.Payload)
|
msg: z.Message,
|
||||||
tasks = append(tasks, &ArchivedTask{
|
state: base.TaskStateArchived,
|
||||||
// TODO: How to handle last failed at
|
|
||||||
Task: t,
|
|
||||||
ID: z.Message.ID.String(),
|
|
||||||
Queue: z.Message.Queue,
|
|
||||||
MaxRetry: z.Message.Retry,
|
|
||||||
Retried: z.Message.Retried,
|
|
||||||
LastFailedAt: failedAt,
|
|
||||||
LastError: z.Message.ErrorMsg,
|
|
||||||
score: z.Score,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return tasks, nil
|
return tasks, nil
|
||||||
|
@ -687,17 +687,11 @@ func TestInspectorListRetryTasks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createArchivedTask(z base.Z) *ArchivedTask {
|
func createArchivedTask(z base.Z) *TaskInfo {
|
||||||
msg := z.Message
|
return &TaskInfo{
|
||||||
return &ArchivedTask{
|
msg: z.Message,
|
||||||
Task: NewTask(msg.Type, msg.Payload),
|
state: base.TaskStateArchived,
|
||||||
ID: msg.ID.String(),
|
nextProcessAt: time.Time{},
|
||||||
Queue: msg.Queue,
|
|
||||||
MaxRetry: msg.Retry,
|
|
||||||
Retried: msg.Retried,
|
|
||||||
LastFailedAt: time.Unix(z.Score, 0),
|
|
||||||
LastError: msg.ErrorMsg,
|
|
||||||
score: z.Score,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -720,7 +714,7 @@ func TestInspectorListArchivedTasks(t *testing.T) {
|
|||||||
desc string
|
desc string
|
||||||
archived map[string][]base.Z
|
archived map[string][]base.Z
|
||||||
qname string
|
qname string
|
||||||
want []*ArchivedTask
|
want []*TaskInfo
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "with a few archived tasks",
|
desc: "with a few archived tasks",
|
||||||
@ -730,7 +724,7 @@ func TestInspectorListArchivedTasks(t *testing.T) {
|
|||||||
},
|
},
|
||||||
qname: "default",
|
qname: "default",
|
||||||
// Should be sorted by LastFailedAt.
|
// Should be sorted by LastFailedAt.
|
||||||
want: []*ArchivedTask{
|
want: []*TaskInfo{
|
||||||
createArchivedTask(z2),
|
createArchivedTask(z2),
|
||||||
createArchivedTask(z1),
|
createArchivedTask(z1),
|
||||||
createArchivedTask(z3),
|
createArchivedTask(z3),
|
||||||
@ -742,7 +736,7 @@ func TestInspectorListArchivedTasks(t *testing.T) {
|
|||||||
"default": {},
|
"default": {},
|
||||||
},
|
},
|
||||||
qname: "default",
|
qname: "default",
|
||||||
want: []*ArchivedTask(nil),
|
want: []*TaskInfo(nil),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -755,8 +749,7 @@ func TestInspectorListArchivedTasks(t *testing.T) {
|
|||||||
t.Errorf("%s; ListArchivedTasks(%q) returned error: %v", tc.desc, tc.qname, err)
|
t.Errorf("%s; ListArchivedTasks(%q) returned error: %v", tc.desc, tc.qname, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ignoreOpt := cmpopts.IgnoreUnexported(Task{}, ArchivedTask{})
|
if diff := cmp.Diff(tc.want, got, cmp.AllowUnexported(TaskInfo{})); diff != "" {
|
||||||
if diff := cmp.Diff(tc.want, got, ignoreOpt); diff != "" {
|
|
||||||
t.Errorf("%s; ListArchivedTask(%q) = %v, want %v; (-want,+got)\n%s",
|
t.Errorf("%s; ListArchivedTask(%q) = %v, want %v; (-want,+got)\n%s",
|
||||||
tc.desc, tc.qname, got, tc.want, diff)
|
tc.desc, tc.qname, got, tc.want, diff)
|
||||||
}
|
}
|
||||||
@ -1983,7 +1976,7 @@ func TestInspectorDeleteTaskDeletesArchivedTask(t *testing.T) {
|
|||||||
"custom": {z3},
|
"custom": {z3},
|
||||||
},
|
},
|
||||||
qname: "default",
|
qname: "default",
|
||||||
id: createArchivedTask(z2).ID,
|
id: createArchivedTask(z2).ID(),
|
||||||
wantArchived: map[string][]base.Z{
|
wantArchived: map[string][]base.Z{
|
||||||
"default": {z1},
|
"default": {z1},
|
||||||
"custom": {z3},
|
"custom": {z3},
|
||||||
@ -2034,7 +2027,7 @@ func TestInspectorDeleteTaskError(t *testing.T) {
|
|||||||
"custom": {z3},
|
"custom": {z3},
|
||||||
},
|
},
|
||||||
qname: "nonexistent",
|
qname: "nonexistent",
|
||||||
id: createArchivedTask(z2).ID,
|
id: createArchivedTask(z2).ID(),
|
||||||
wantErr: ErrQueueNotFound,
|
wantErr: ErrQueueNotFound,
|
||||||
wantArchived: map[string][]base.Z{
|
wantArchived: map[string][]base.Z{
|
||||||
"default": {z1, z2},
|
"default": {z1, z2},
|
||||||
@ -2245,7 +2238,7 @@ func TestInspectorRunTaskRunsArchivedTask(t *testing.T) {
|
|||||||
"low": {},
|
"low": {},
|
||||||
},
|
},
|
||||||
qname: "critical",
|
qname: "critical",
|
||||||
id: createArchivedTask(z2).ID,
|
id: createArchivedTask(z2).ID(),
|
||||||
wantArchived: map[string][]base.Z{
|
wantArchived: map[string][]base.Z{
|
||||||
"default": {z1},
|
"default": {z1},
|
||||||
"critical": {},
|
"critical": {},
|
||||||
@ -2319,7 +2312,7 @@ func TestInspectorRunTaskError(t *testing.T) {
|
|||||||
"low": {},
|
"low": {},
|
||||||
},
|
},
|
||||||
qname: "nonexistent",
|
qname: "nonexistent",
|
||||||
id: createArchivedTask(z2).ID,
|
id: createArchivedTask(z2).ID(),
|
||||||
wantErr: ErrQueueNotFound,
|
wantErr: ErrQueueNotFound,
|
||||||
wantArchived: map[string][]base.Z{
|
wantArchived: map[string][]base.Z{
|
||||||
"default": {z1},
|
"default": {z1},
|
||||||
|
Loading…
Reference in New Issue
Block a user