tirkarthi commented on code in PR #35863: URL: https://github.com/apache/airflow/pull/35863#discussion_r1406630494
########## airflow/www/static/js/dag/details/taskDuration/index.tsx: ########## @@ -0,0 +1,143 @@ +/*! + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from "react"; +import { Box } from "@chakra-ui/react"; + +import useSelection from "src/dag/useSelection"; +import { useGridData } from "src/api"; +import { getDuration, formatDateTime } from "src/datetime_utils"; +import ReactECharts, { ReactEChartsProps } from "src/components/ReactECharts"; + +const TaskDuration = () => { + const { + selected: { taskId }, + onSelect, + } = useSelection(); + + const { + data: { groups }, + } = useGridData(); + var maxDuration = 0; + var unit = "seconds"; + var factor = 1; + + const taskInstances = groups.children.filter( + (instance) => instance.id === taskId + )[0].instances; + taskInstances.forEach((instance) => { + const runDuration = + instance?.startDate && instance?.endDate + ? getDuration(instance?.startDate, instance?.endDate) / 1000 + : 0; + const queuedDuration = + instance?.queuedDttm && instance?.startDate > instance.queuedDttm + ? getDuration(instance?.queuedDttm, instance?.startDate) / 1000 + : 0; + + if (runDuration > maxDuration) { + maxDuration = runDuration; + } + + instance.runDuration = runDuration; + instance.queuedDuration = queuedDuration; + }); + + if (maxDuration <= 60 * 2) { Review Comment: There is a long feature request for this that was not implemented in moment.js and current humanize method is not relevant for usage here. This calculation is from the existing duration page Python logic ported to JS. I have kept it to get the unit (seconds, hours) and used moment methods asSeconds, asMinutes based on the unit instead of doing the math on own as before. I would like to hear your thoughts on normalization of the time period unit to fit the chart better. https://github.com/moment/moment/issues/348 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
