2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-04-22 16:50:18 +08:00

Add GetTaskInfo method to Inspector

This commit is contained in:
Ken Hibino 2021-03-31 07:19:32 -07:00
parent da823fb26a
commit 57fc8b86e2

View File

@ -175,46 +175,90 @@ func (i *Inspector) DeleteQueue(qname string, force bool) error {
} }
// TaskInfo describes a task. // TaskInfo describes a task.
type TaskInfo interface { type TaskInfo struct {
// ID returns the unique identifier of the task. info *base.TaskInfo
ID() string }
// Type returns the type name of the task. // ID returns the unique identifier of the task.
Type() string func (t *TaskInfo) ID() string {
return t.info.ID.String()
}
// Payload returns the payload data of the task. // Type returns the type name of the task.
Payload() []byte func (t *TaskInfo) Type() string {
return t.info.Type
}
// State returns a TaskState representing the state of the task. // Payload returns the payload data of the task.
State() TaskState func (t *TaskInfo) Payload() []byte {
return t.info.Payload
}
// Queue returns the name of the queue the task belongs to. // State returns a TaskState representing the state of the task.
Queue() string func (t *TaskInfo) State() TaskState {
switch t.info.State {
case "active":
return TaskStateActive
case "pending":
return TaskStatePending
case "scheduled":
return TaskStateScheduled
case "retry":
return TaskStateRetry
case "archived":
return TaskStateArchived
}
panic("asynq internal error: unknown state")
}
// MaxRetry returns the maximum number of times the task can be retried. // Queue returns the name of the queue the task belongs to.
MaxRetry() int func (t *TaskInfo) Queue() string {
return t.info.Queue
}
// Retried returns the number of times the task has been retried. // MaxRetry returns the maximum number of times the task can be retried.
Retried() int func (t *TaskInfo) MaxRetry() int {
return t.info.Retry
}
// Deadline returns the deadline set for the task. // Retried returns the number of times the task has been retried.
Deadline() time.Time func (t *TaskInfo) Retried() int {
return t.info.Retried
}
// Timeout returns the timeout duration set for the task. // Deadline returns the deadline set for the task.
Timeout() time.Duration func (t *TaskInfo) Deadline() time.Time {
return time.Unix(t.info.Deadline, 0)
}
// NextProcessAt returns the time the task will be ready to be processed. // Timeout returns the timeout duration set for the task.
// Zero value of time.Time is used when task is in pending, active, or archived func (t *TaskInfo) Timeout() time.Duration {
// state. return time.Duration(t.info.Timeout) * time.Second
NextProcessAt() time.Time }
// LastFailedAt returns the time the task last failed. // NextProcessAt returns the time the task will be ready to be processed.
// Zero value of time.Time is used if the task has not failed. // Zero value of time.Time is used when task is in active or archived
LastFailedAt() time.Time // state.
func (t *TaskInfo) NextProcessAt() time.Time {
if t.info.NextProcessAt == 0 {
return time.Time{}
}
return time.Unix(t.info.NextProcessAt, 0)
}
// LastErr returns the error message from the last failure. // LastFailedAt returns the time the task last failed.
// Empty string is returned if the task has not failed. // Zero value of time.Time is used if the task has not failed.
LastErr() string func (t *TaskInfo) LastFailedAt() time.Time {
if t.info.LastFailedAt == 0 {
return time.Time{}
}
return time.Unix(t.info.LastFailedAt, 0)
}
// LastErr returns the error message from the last failure.
// Empty string is returned if the task has not failed.
func (t *TaskInfo) LastErr() string {
return t.info.ErrorMsg
} }
// TaskState represents the state of a task. // TaskState represents the state of a task.
@ -228,9 +272,12 @@ const (
TaskStateArchived TaskStateArchived
) )
func (i *Inspector) GetTaskInfo(qname, id string) (TaskInfo, error) { func (i *Inspector) GetTaskInfo(qname, id string) (*TaskInfo, error) {
// TODO: implement this info, err := i.rdb.GetTaskInfo(qname, id)
return nil, nil if err != nil {
return nil, err
}
return &TaskInfo{info}, nil
} }
// PendingTask is a task in a queue and is ready to be processed. // PendingTask is a task in a queue and is ready to be processed.