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

Add Retry and LastError fields to inspector tasks

This commit is contained in:
Ken Hibino 2021-01-27 06:59:32 -08:00
parent afde6a7266
commit bfde0b6283
3 changed files with 57 additions and 24 deletions

View File

@ -7,9 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- `ErrorMsg` field in `RetryTask` and `ArchivedTask` was renamed to `LastError`.
### Added
- `MemoryUsage` field is added to `QueueStats`.
- `MaxRetry`, `Retried`, `LastError` fields were added to all task types returned from `Inspector`.
- `MemoryUsage` field was added to `QueueStats`.
- `DeleteAllPendingTasks`, `ArchiveAllPendingTasks` were added to `Inspector`
- `DeleteTaskByKey` and `ArchiveTaskByKey` now supports deleting/archiving `PendingTask`.
- asynq CLI now supports deleting/archiving pending tasks.

View File

@ -171,6 +171,9 @@ type PendingTask struct {
*Task
ID string
Queue string
MaxRetry int
Retried int
LastError string
}
// ActiveTask is a task that's currently being processed.
@ -178,6 +181,9 @@ type ActiveTask struct {
*Task
ID string
Queue string
MaxRetry int
Retried int
LastError string
}
// ScheduledTask is a task scheduled to be processed in the future.
@ -185,6 +191,9 @@ type ScheduledTask struct {
*Task
ID string
Queue string
MaxRetry int
Retried int
LastError string
NextProcessAt time.Time
score int64
@ -198,7 +207,7 @@ type RetryTask struct {
NextProcessAt time.Time
MaxRetry int
Retried int
ErrorMsg string
LastError string
// TODO: LastFailedAt time.Time
score int64
@ -215,7 +224,7 @@ type ArchivedTask struct {
MaxRetry int
Retried int
LastFailedAt time.Time
ErrorMsg string
LastError string
score int64
}
@ -358,6 +367,9 @@ func (i *Inspector) ListPendingTasks(qname string, opts ...ListOption) ([]*Pendi
Task: NewTask(m.Type, m.Payload),
ID: m.ID.String(),
Queue: m.Queue,
MaxRetry: m.Retry,
Retried: m.Retried,
LastError: m.ErrorMsg,
})
}
return tasks, err
@ -378,10 +390,14 @@ func (i *Inspector) ListActiveTasks(qname string, opts ...ListOption) ([]*Active
}
var tasks []*ActiveTask
for _, m := range msgs {
tasks = append(tasks, &ActiveTask{
Task: NewTask(m.Type, m.Payload),
ID: m.ID.String(),
Queue: m.Queue,
MaxRetry: m.Retry,
Retried: m.Retried,
LastError: m.ErrorMsg,
})
}
return tasks, err
@ -409,6 +425,9 @@ func (i *Inspector) ListScheduledTasks(qname string, opts ...ListOption) ([]*Sch
Task: t,
ID: z.Message.ID.String(),
Queue: z.Message.Queue,
MaxRetry: z.Message.Retry,
Retried: z.Message.Retried,
LastError: z.Message.ErrorMsg,
NextProcessAt: processAt,
score: z.Score,
})
@ -442,7 +461,7 @@ func (i *Inspector) ListRetryTasks(qname string, opts ...ListOption) ([]*RetryTa
MaxRetry: z.Message.Retry,
Retried: z.Message.Retried,
// TODO: LastFailedAt: z.Message.LastFailedAt
ErrorMsg: z.Message.ErrorMsg,
LastError: z.Message.ErrorMsg,
score: z.Score,
})
}
@ -474,7 +493,7 @@ func (i *Inspector) ListArchivedTasks(qname string, opts ...ListOption) ([]*Arch
MaxRetry: z.Message.Retry,
Retried: z.Message.Retried,
LastFailedAt: failedAt,
ErrorMsg: z.Message.ErrorMsg,
LastError: z.Message.ErrorMsg,
score: z.Score,
})
}

View File

@ -426,6 +426,9 @@ func createPendingTask(msg *base.TaskMessage) *PendingTask {
Task: NewTask(msg.Type, msg.Payload),
ID: msg.ID.String(),
Queue: msg.Queue,
MaxRetry: msg.Retry,
Retried: msg.Retried,
LastError: msg.ErrorMsg,
}
}
@ -513,6 +516,9 @@ func TestInspectorListActiveTasks(t *testing.T) {
Task: NewTask(msg.Type, msg.Payload),
ID: msg.ID.String(),
Queue: msg.Queue,
MaxRetry: msg.Retry,
Retried: msg.Retried,
LastError: msg.ErrorMsg,
}
}
@ -559,6 +565,9 @@ func createScheduledTask(z base.Z) *ScheduledTask {
Task: NewTask(msg.Type, msg.Payload),
ID: msg.ID.String(),
Queue: msg.Queue,
MaxRetry: msg.Retry,
Retried: msg.Retried,
LastError: msg.ErrorMsg,
NextProcessAt: time.Unix(z.Score, 0),
score: z.Score,
}
@ -635,7 +644,7 @@ func createRetryTask(z base.Z) *RetryTask {
NextProcessAt: time.Unix(z.Score, 0),
MaxRetry: msg.Retry,
Retried: msg.Retried,
ErrorMsg: msg.ErrorMsg,
LastError: msg.ErrorMsg,
score: z.Score,
}
}
@ -712,7 +721,7 @@ func createArchivedTask(z base.Z) *ArchivedTask {
MaxRetry: msg.Retry,
Retried: msg.Retried,
LastFailedAt: time.Unix(z.Score, 0),
ErrorMsg: msg.ErrorMsg,
LastError: msg.ErrorMsg,
score: z.Score,
}
}