Add retry and last error fields to all task types

This commit is contained in:
Ken Hibino 2021-01-27 07:18:31 -08:00
parent a488599ec0
commit 3c43624927
3 changed files with 63 additions and 42 deletions

View File

@ -84,10 +84,13 @@ func toDailyStatsList(in []*asynq.DailyStats) []*DailyStats {
} }
type BaseTask struct { type BaseTask struct {
ID string `json:"id"` ID string `json:"id"`
Type string `json:"type"` Type string `json:"type"`
Payload asynq.Payload `json:"payload"` Payload asynq.Payload `json:"payload"`
Queue string `json:"queue"` Queue string `json:"queue"`
MaxRetry int `json:"max_retry"`
Retried int `json:"retried"`
LastError string `json:"error_message"`
} }
type ActiveTask struct { type ActiveTask struct {
@ -103,10 +106,13 @@ type ActiveTask struct {
func toActiveTask(t *asynq.ActiveTask) *ActiveTask { func toActiveTask(t *asynq.ActiveTask) *ActiveTask {
base := &BaseTask{ base := &BaseTask{
ID: t.ID, ID: t.ID,
Type: t.Type, Type: t.Type,
Payload: t.Payload, Payload: t.Payload,
Queue: t.Queue, Queue: t.Queue,
MaxRetry: t.MaxRetry,
Retried: t.Retried,
LastError: t.LastError,
} }
return &ActiveTask{BaseTask: base} return &ActiveTask{BaseTask: base}
} }
@ -126,10 +132,13 @@ type PendingTask struct {
func toPendingTask(t *asynq.PendingTask) *PendingTask { func toPendingTask(t *asynq.PendingTask) *PendingTask {
base := &BaseTask{ base := &BaseTask{
ID: t.ID, ID: t.ID,
Type: t.Type, Type: t.Type,
Payload: t.Payload, Payload: t.Payload,
Queue: t.Queue, Queue: t.Queue,
MaxRetry: t.MaxRetry,
Retried: t.Retried,
LastError: t.LastError,
} }
return &PendingTask{ return &PendingTask{
BaseTask: base, BaseTask: base,
@ -153,10 +162,13 @@ type ScheduledTask struct {
func toScheduledTask(t *asynq.ScheduledTask) *ScheduledTask { func toScheduledTask(t *asynq.ScheduledTask) *ScheduledTask {
base := &BaseTask{ base := &BaseTask{
ID: t.ID, ID: t.ID,
Type: t.Type, Type: t.Type,
Payload: t.Payload, Payload: t.Payload,
Queue: t.Queue, Queue: t.Queue,
MaxRetry: t.MaxRetry,
Retried: t.Retried,
LastError: t.LastError,
} }
return &ScheduledTask{ return &ScheduledTask{
BaseTask: base, BaseTask: base,
@ -177,25 +189,22 @@ type RetryTask struct {
*BaseTask *BaseTask
Key string `json:"key"` Key string `json:"key"`
NextProcessAt time.Time `json:"next_process_at"` NextProcessAt time.Time `json:"next_process_at"`
MaxRetry int `json:"max_retry"`
Retried int `json:"retried"`
ErrorMsg string `json:"error_message"`
} }
func toRetryTask(t *asynq.RetryTask) *RetryTask { func toRetryTask(t *asynq.RetryTask) *RetryTask {
base := &BaseTask{ base := &BaseTask{
ID: t.ID, ID: t.ID,
Type: t.Type, Type: t.Type,
Payload: t.Payload, Payload: t.Payload,
Queue: t.Queue, Queue: t.Queue,
MaxRetry: t.MaxRetry,
Retried: t.Retried,
LastError: t.LastError,
} }
return &RetryTask{ return &RetryTask{
BaseTask: base, BaseTask: base,
Key: t.Key(), Key: t.Key(),
NextProcessAt: t.NextProcessAt, NextProcessAt: t.NextProcessAt,
MaxRetry: t.MaxRetry,
Retried: t.Retried,
ErrorMsg: t.ErrorMsg,
} }
} }
@ -210,25 +219,22 @@ func toRetryTasks(in []*asynq.RetryTask) []*RetryTask {
type ArchivedTask struct { type ArchivedTask struct {
*BaseTask *BaseTask
Key string `json:"key"` Key string `json:"key"`
MaxRetry int `json:"max_retry"`
Retried int `json:"retried"`
ErrorMsg string `json:"error_message"`
LastFailedAt time.Time `json:"last_failed_at"` LastFailedAt time.Time `json:"last_failed_at"`
} }
func toArchivedTask(t *asynq.ArchivedTask) *ArchivedTask { func toArchivedTask(t *asynq.ArchivedTask) *ArchivedTask {
base := &BaseTask{ base := &BaseTask{
ID: t.ID, ID: t.ID,
Type: t.Type, Type: t.Type,
Payload: t.Payload, Payload: t.Payload,
Queue: t.Queue, Queue: t.Queue,
MaxRetry: t.MaxRetry,
Retried: t.Retried,
LastError: t.LastError,
} }
return &ArchivedTask{ return &ArchivedTask{
BaseTask: base, BaseTask: base,
Key: t.Key(), Key: t.Key(),
MaxRetry: t.MaxRetry,
Retried: t.Retried,
ErrorMsg: t.ErrorMsg,
LastFailedAt: t.LastFailedAt, LastFailedAt: t.LastFailedAt,
} }
} }

View File

@ -249,18 +249,27 @@ export interface ActiveTask extends BaseTask {
id: string; id: string;
queue: string; queue: string;
start_time: string; start_time: string;
max_retry: number;
retried: number;
error_message: string;
} }
export interface PendingTask extends BaseTask { export interface PendingTask extends BaseTask {
id: string; id: string;
key: string; key: string;
queue: string; queue: string;
max_retry: number;
retried: number;
error_message: string;
} }
export interface ScheduledTask extends BaseTask { export interface ScheduledTask extends BaseTask {
id: string; id: string;
key: string; key: string;
queue: string; queue: string;
max_retry: number;
retried: number;
error_message: string;
next_process_at: string; next_process_at: string;
} }

View File

@ -392,21 +392,27 @@ function Row(props: RowProps) {
<TableBody> <TableBody>
<TableRow> <TableRow>
<TableCell>Retry</TableCell> <TableCell>Retry</TableCell>
<TableCell align="right">2/25</TableCell> <TableCell align="right">
{task.retried}/{task.max_retry}
</TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell>Deadline</TableCell> <TableCell>Last Error</TableCell>
<TableCell align="right">In 30s</TableCell> <TableCell align="right">
{task.error_message.length > 0
? task.error_message
: "N/A"}
</TableCell>
</TableRow> </TableRow>
<TableRow> <TableRow>
<TableCell className={classes.noBottomBorder}> <TableCell className={classes.noBottomBorder}>
Unique Deadline
</TableCell> </TableCell>
<TableCell <TableCell
align="right"
className={classes.noBottomBorder} className={classes.noBottomBorder}
align="right"
> >
5m30s remaining TODO: In 30s
</TableCell> </TableCell>
</TableRow> </TableRow>
</TableBody> </TableBody>