Skip to content

Commit

Permalink
Shows outdated tasks as stale (#954)
Browse files Browse the repository at this point in the history
* Shows outdated tasks as interrupted

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Use stale instead of interrupted

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Remove config parameter, change status display string only

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Remove unused resource config

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

* Fix merge conflict bug where statuses and finish time are always warning colored

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>

---------

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Jun 12, 2024
1 parent bd06c2d commit 6ad01a4
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions packages/react-components/lib/tasks/task-table-datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ const StyledDataGrid = styled(DataGrid)(({ theme }) => ({
},
}));

function isTaskOutdated(taskState: TaskState): boolean {
if (
!taskState.unix_millis_finish_time ||
!taskState.status ||
(taskState.status !== Status.Underway && taskState.status !== Status.Queued)
) {
return false;
}

const finishDateTime = new Date(taskState.unix_millis_finish_time);
const nowDateTime = new Date();
return nowDateTime > finishDateTime;
}

export interface Tasks {
isLoading: boolean;
data: TaskState[];
Expand Down Expand Up @@ -317,6 +331,29 @@ export function TaskDataGridTable({
editable: false,
valueGetter: (params: GridValueGetterParams) =>
params.row.state.status ? params.row.state.status : 'unknown',
renderCell: (cellValues) => {
const statusString = cellValues.row.state.status ? cellValues.row.state.status : 'unknown';
if (isTaskOutdated(cellValues.row.state)) {
return (
<Tooltip
title={
<React.Fragment>
<Typography>
Finish time is in the past, but task is still queued or underway.
</Typography>
<Typography>
The task may have been interrupted or stalled during the execution.
</Typography>
</React.Fragment>
}
>
<Box component="div">{`${statusString} (stale)`}</Box>
</Tooltip>
);
}

return <Box component="div">{statusString}</Box>;
},
flex: 1,
filterOperators: getMinimalStringFilterOperators,
filterable: true,
Expand Down Expand Up @@ -370,6 +407,10 @@ export function TaskDataGridTable({
onRowClick={handleEvent}
getCellClassName={(params: GridCellParams<string>) => {
if (params.field === 'status') {
if (isTaskOutdated(params.row.state)) {
return classes.taskUnknownCell;
}

switch (params.value) {
case Status.Underway:
return classes.taskActiveCell;
Expand All @@ -385,7 +426,7 @@ export function TaskDataGridTable({
return classes.taskUnknownCell;
}
} else if (params.field === 'unix_millis_finish_time') {
if (!params.value) {
if (!params.row.state.unix_millis_finish_time) {
return classes.taskUnknownCell;
}

Expand All @@ -399,7 +440,9 @@ export function TaskDataGridTable({
}
}

const finishDateTime = params.value ? new Date(params.value) : undefined;
const finishDateTime = params.row.state.unix_millis_finish_time
? new Date(params.row.state.unix_millis_finish_time)
: undefined;

if (warnDateTime && finishDateTime && finishDateTime > warnDateTime) {
return classes.taskLateCell;
Expand Down

0 comments on commit 6ad01a4

Please sign in to comment.