Skip to content

Commit f2a15d4

Browse files
bbovenziephraimbuddy
authored andcommitted
Fix Gantt Task Tries (#41342)
(cherry picked from commit cb80bda)
1 parent 1002266 commit f2a15d4

3 files changed

Lines changed: 57 additions & 33 deletions

File tree

airflow/www/static/js/dag/details/gantt/Row.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ const Row = ({
6969
const isSelected = taskId === instance?.taskId;
7070
const isOpen = openGroupIds.includes(task.id || "");
7171

72+
// Adjust gantt start/end if the instance dates are out of bounds
73+
useEffect(() => {
74+
if (setGanttDuration) {
75+
setGanttDuration(
76+
instance?.queuedDttm,
77+
instance?.startDate,
78+
instance?.endDate
79+
);
80+
}
81+
}, [instance, setGanttDuration]);
82+
7283
// Adjust gantt start/end if the ti history dates are out of bounds
7384
useEffect(() => {
7485
tiHistory?.taskInstances?.forEach(
@@ -91,6 +102,7 @@ const Row = ({
91102
>
92103
{!!instance && (
93104
<InstanceBar
105+
key={`${instance.taskId}-${instance.tryNumber}`}
94106
instance={{
95107
...instance,
96108
queuedWhen: instance.queuedDttm,
@@ -102,16 +114,19 @@ const Row = ({
102114
ganttEndDate={ganttEndDate}
103115
/>
104116
)}
105-
{tiHistory?.taskInstances?.map((ti) => (
106-
<InstanceBar
107-
key={`${taskId}-${ti.tryNumber}`}
108-
instance={ti}
109-
task={task}
110-
ganttWidth={ganttWidth}
111-
ganttStartDate={ganttStartDate}
112-
ganttEndDate={ganttEndDate}
113-
/>
114-
))}
117+
{tiHistory?.taskInstances?.map(
118+
(ti) =>
119+
ti.tryNumber !== instance?.tryNumber && (
120+
<InstanceBar
121+
key={`${ti.taskId}-${ti.tryNumber}`}
122+
instance={ti}
123+
task={task}
124+
ganttWidth={ganttWidth}
125+
ganttStartDate={ganttStartDate}
126+
ganttEndDate={ganttEndDate}
127+
/>
128+
)
129+
)}
115130
</Box>
116131
{isOpen &&
117132
!!task.children &&

airflow/www/static/js/dag/details/gantt/index.tsx

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,34 @@
2020
import React, { useCallback, useEffect, useRef, useState } from "react";
2121
import { Alert, AlertIcon, Box, Divider, Text } from "@chakra-ui/react";
2222

23-
import useSelection from "src/dag/useSelection";
2423
import { useGridData } from "src/api";
2524
import Time from "src/components/Time";
2625
import { getDuration } from "src/datetime_utils";
2726

2827
import Row from "./Row";
2928

3029
interface Props {
30+
runId: string | null;
31+
taskId: string | null;
3132
openGroupIds: string[];
3233
gridScrollRef: React.RefObject<HTMLDivElement>;
3334
ganttScrollRef: React.RefObject<HTMLDivElement>;
3435
}
3536

36-
const Gantt = ({ openGroupIds, gridScrollRef, ganttScrollRef }: Props) => {
37+
const Gantt = ({
38+
runId,
39+
taskId,
40+
openGroupIds,
41+
gridScrollRef,
42+
ganttScrollRef,
43+
}: Props) => {
3744
const ganttRef = useRef<HTMLDivElement>(null);
3845
const [top, setTop] = useState(0);
3946
const [width, setWidth] = useState(500);
4047
const [height, setHeight] = useState("100%");
41-
const {
42-
selected: { runId, taskId },
43-
} = useSelection();
48+
const [startDate, setStartDate] = useState<string | null | undefined>();
49+
const [endDate, setEndDate] = useState<string | null | undefined>();
50+
4451
const {
4552
data: { dagRuns, groups },
4653
} = useGridData();
@@ -106,15 +113,6 @@ const Gantt = ({ openGroupIds, gridScrollRef, ganttScrollRef }: Props) => {
106113

107114
const dagRun = dagRuns.find((dr) => dr.runId === runId);
108115

109-
const [startDate, setStartDate] = useState(
110-
dagRun?.queuedAt || dagRun?.startDate
111-
);
112-
113-
const [endDate, setEndDate] = useState(
114-
// @ts-ignore
115-
dagRun?.endDate ?? moment().add(1, "s").toString()
116-
);
117-
118116
// Check if any task instance dates are outside the bounds of the dag run dates and update our min start and max end
119117
const setGanttDuration = useCallback(
120118
(
@@ -136,21 +134,30 @@ const Gantt = ({ openGroupIds, gridScrollRef, ganttScrollRef }: Props) => {
136134

137135
if (end && (!endDate || Date.parse(end) > Date.parse(endDate))) {
138136
setEndDate(end);
137+
} else if (!end) {
138+
// @ts-ignore
139+
setEndDate(moment().add(1, "s").toString());
139140
}
140141
},
141142
[startDate, endDate, setStartDate, setEndDate]
142143
);
143144

145+
// Reset state when the dagrun changes
144146
useEffect(() => {
145-
groups.children?.forEach((task) => {
146-
const taskInstance = task.instances.find((ti) => ti.runId === runId);
147-
setGanttDuration(
148-
taskInstance?.queuedDttm,
149-
taskInstance?.startDate,
150-
taskInstance?.endDate
151-
);
152-
});
153-
}, [groups.children, runId, setGanttDuration]);
147+
if (startDate !== dagRun?.queuedAt && startDate !== dagRun?.startDate) {
148+
setStartDate(dagRun?.queuedAt || dagRun?.startDate);
149+
}
150+
if (!endDate || endDate !== dagRun?.endDate) {
151+
// @ts-ignore
152+
setEndDate(dagRun?.endDate ?? moment().add(1, "s").toString());
153+
}
154+
}, [
155+
dagRun?.queuedAt,
156+
dagRun?.startDate,
157+
dagRun?.endDate,
158+
startDate,
159+
endDate,
160+
]);
154161

155162
const numBars = Math.round(width / 100);
156163
const runDuration = getDuration(startDate, endDate);

airflow/www/static/js/dag/details/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ const Details = ({
449449
openGroupIds={openGroupIds}
450450
gridScrollRef={gridScrollRef}
451451
ganttScrollRef={ganttScrollRef}
452+
taskId={taskId}
453+
runId={runId}
452454
/>
453455
</TabPanel>
454456
<TabPanel height="100%">

0 commit comments

Comments
 (0)