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

Define TaskInfo and TaskState

This commit is contained in:
Ken Hibino 2021-03-23 07:03:36 -07:00
parent d9481bd524
commit 12ed810cfc

View File

@ -173,6 +173,49 @@ func (i *Inspector) DeleteQueue(qname string, force bool) error {
return err return err
} }
// TaskInfo describes a task.
type TaskInfo interface {
// ID returns the unique identifier of the task.
ID() string
// Type returns the type name of the task.
Type() string
// Payload returns the payload data of the task.
Payload() []byte
// State returns a TaskState representing the state of the task.
State() TaskState
// Queue returns the name of the queue the task belongs to.
Queue() string
// MaxRetry returns the maximum number of times the task can be retried.
MaxRetry() int
// Retried returns the number of times the task has been retried.
Retried() int
// Deadline returns the deadline set for the task.
Deadline() time.Time
// Timeout returns the timeout duration set for the task.
Timeout() time.Duration
// NextProcessAt returns the time the task will be ready to be processed.
// Zero value of time.Time is used when task is in pending, active, or archived
// state.
NextProcessAt() time.Time
// LastFailedAt returns the time the task last failed.
// Zero value of time.Time is used if the task has not failed.
LastFailedAt() time.Time
// LastErr returns the error message from the last failure.
// Empty string is returned if the task has not failed.
LastErr() string
}
// TaskState represents the state of a task.
type TaskState int
const (
TaskStatePending TaskState = iota
TaskStateActive
TaskStateScheduled
TaskStateRetry
TaskStateArchived
)
// 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.
type PendingTask struct { type PendingTask struct {
*asynq.Task *asynq.Task