From 12ed810cfcb1a7bf596b1f783f8a7601e788e31c Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Tue, 23 Mar 2021 07:03:36 -0700 Subject: [PATCH] Define TaskInfo and TaskState --- inspeq/inspector.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/inspeq/inspector.go b/inspeq/inspector.go index 49a99c8..d1ad262 100644 --- a/inspeq/inspector.go +++ b/inspeq/inspector.go @@ -173,6 +173,49 @@ func (i *Inspector) DeleteQueue(qname string, force bool) error { 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. type PendingTask struct { *asynq.Task