mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 03:05:53 +08:00
Show deadline data in ActiveTasksTable
This commit is contained in:
parent
3c43624927
commit
ae7e0730bc
@ -102,6 +102,12 @@ type ActiveTask struct {
|
|||||||
// a worker started working on the task only a few moments ago, and started time
|
// a worker started working on the task only a few moments ago, and started time
|
||||||
// data is not available.
|
// data is not available.
|
||||||
Started string `json:"start_time"`
|
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 {
|
func toActiveTask(t *asynq.ActiveTask) *ActiveTask {
|
||||||
|
@ -43,22 +43,24 @@ func newListActiveTasksHandlerFunc(inspector *asynq.Inspector) http.HandlerFunc
|
|||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// m maps taskID to started time.
|
// m maps taskID to WorkerInfo.
|
||||||
m := make(map[string]time.Time)
|
m := make(map[string]*asynq.WorkerInfo)
|
||||||
for _, srv := range servers {
|
for _, srv := range servers {
|
||||||
for _, w := range srv.ActiveWorkers {
|
for _, w := range srv.ActiveWorkers {
|
||||||
if w.Task.Queue == qname {
|
if w.Task.Queue == qname {
|
||||||
m[w.Task.ID] = w.Started
|
m[w.Task.ID] = w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
activeTasks := toActiveTasks(tasks)
|
activeTasks := toActiveTasks(tasks)
|
||||||
for _, t := range activeTasks {
|
for _, t := range activeTasks {
|
||||||
started, ok := m[t.ID]
|
workerInfo, ok := m[t.ID]
|
||||||
if ok {
|
if ok {
|
||||||
t.Started = started.Format(time.RFC3339)
|
t.Started = workerInfo.Started.Format(time.RFC3339)
|
||||||
|
t.Deadline = workerInfo.Deadline.Format(time.RFC3339)
|
||||||
} else {
|
} else {
|
||||||
t.Started = "-"
|
t.Started = "-"
|
||||||
|
t.Deadline = "-"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,6 +249,7 @@ export interface ActiveTask extends BaseTask {
|
|||||||
id: string;
|
id: string;
|
||||||
queue: string;
|
queue: string;
|
||||||
start_time: string;
|
start_time: string;
|
||||||
|
deadline: string;
|
||||||
max_retry: number;
|
max_retry: number;
|
||||||
retried: number;
|
retried: number;
|
||||||
error_message: string;
|
error_message: string;
|
||||||
|
@ -37,7 +37,7 @@ import TablePaginationActions, {
|
|||||||
import TableActions from "./TableActions";
|
import TableActions from "./TableActions";
|
||||||
import { usePolling } from "../hooks";
|
import { usePolling } from "../hooks";
|
||||||
import { ActiveTaskExtended } from "../reducers/tasksReducer";
|
import { ActiveTaskExtended } from "../reducers/tasksReducer";
|
||||||
import { timeAgo, uuidPrefix } from "../utils";
|
import { durationBefore, timeAgo, uuidPrefix } from "../utils";
|
||||||
import { TableColumn } from "../types/table";
|
import { TableColumn } from "../types/table";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
@ -412,7 +412,9 @@ function Row(props: RowProps) {
|
|||||||
className={classes.noBottomBorder}
|
className={classes.noBottomBorder}
|
||||||
align="right"
|
align="right"
|
||||||
>
|
>
|
||||||
TODO: In 30s
|
{task.deadline === "-"
|
||||||
|
? "-"
|
||||||
|
: durationBefore(task.deadline)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
|
Loading…
Reference in New Issue
Block a user