diff --git a/conversion_helpers.go b/conversion_helpers.go index 688e7ff..92551d8 100644 --- a/conversion_helpers.go +++ b/conversion_helpers.go @@ -102,6 +102,12 @@ type ActiveTask struct { // a worker started working on the task only a few moments ago, and started time // data is not available. Started string `json:"start_time"` + + // Deadline indicates the time by which the worker needs to finish its task. + // + // Value is either time formatted in RFC3339 format, or "-" which indicates that + // the data is not available yet. + Deadline string `json:"deadline"` } func toActiveTask(t *asynq.ActiveTask) *ActiveTask { diff --git a/task_handlers.go b/task_handlers.go index a4642ea..e4a4a3c 100644 --- a/task_handlers.go +++ b/task_handlers.go @@ -43,22 +43,24 @@ func newListActiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc http.Error(w, err.Error(), http.StatusInternalServerError) return } - // m maps taskID to started time. - m := make(map[string]time.Time) + // m maps taskID to WorkerInfo. + m := make(map[string]*asynq.WorkerInfo) for _, srv := range servers { for _, w := range srv.ActiveWorkers { if w.Task.Queue == qname { - m[w.Task.ID] = w.Started + m[w.Task.ID] = w } } } activeTasks := toActiveTasks(tasks) for _, t := range activeTasks { - started, ok := m[t.ID] + workerInfo, ok := m[t.ID] if ok { - t.Started = started.Format(time.RFC3339) + t.Started = workerInfo.Started.Format(time.RFC3339) + t.Deadline = workerInfo.Deadline.Format(time.RFC3339) } else { t.Started = "-" + t.Deadline = "-" } } diff --git a/ui/src/api.ts b/ui/src/api.ts index 4c04d97..1900c2c 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -249,6 +249,7 @@ export interface ActiveTask extends BaseTask { id: string; queue: string; start_time: string; + deadline: string; max_retry: number; retried: number; error_message: string; diff --git a/ui/src/components/ActiveTasksTable.tsx b/ui/src/components/ActiveTasksTable.tsx index f76453b..8675290 100644 --- a/ui/src/components/ActiveTasksTable.tsx +++ b/ui/src/components/ActiveTasksTable.tsx @@ -37,7 +37,7 @@ import TablePaginationActions, { import TableActions from "./TableActions"; import { usePolling } from "../hooks"; import { ActiveTaskExtended } from "../reducers/tasksReducer"; -import { timeAgo, uuidPrefix } from "../utils"; +import { durationBefore, timeAgo, uuidPrefix } from "../utils"; import { TableColumn } from "../types/table"; const useStyles = makeStyles((theme) => ({ @@ -412,7 +412,9 @@ function Row(props: RowProps) { className={classes.noBottomBorder} align="right" > - TODO: In 30s + {task.deadline === "-" + ? "-" + : durationBefore(task.deadline)}