tirkarthi commented on code in PR #44604: URL: https://github.com/apache/airflow/pull/44604#discussion_r1869702361
########## airflow/ui/src/pages/DagsList/Dag/Tasks/Tasks.tsx: ########## @@ -0,0 +1,112 @@ +/*! + * 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 { Heading, Skeleton, Box } from "@chakra-ui/react"; +import { useParams } from "react-router-dom"; + +import { + useTaskServiceGetTasks, + useTaskInstanceServiceGetTaskInstances, + useDagsServiceRecentDagRuns, +} from "openapi/queries"; +import type { + TaskResponse, + TaskInstanceResponse, +} from "openapi/requests/types.gen"; +import { DataTable } from "src/components/DataTable"; +import type { CardDef } from "src/components/DataTable/types"; +import { ErrorAlert } from "src/components/ErrorAlert"; + +import { TaskCard } from "./TaskCard"; + +const cardDef = ( + taskInstances?: Array<TaskInstanceResponse>, +): CardDef<TaskResponse> => ({ + card: ({ row }) => ( + <TaskCard + task={row} + taskInstance={ + taskInstances + ? taskInstances.filter( + (instance: TaskInstanceResponse) => + instance.task_id === row.task_id, + ) + : [] + } + /> + ), + meta: { + customSkeleton: <Skeleton height="120px" width="100%" />, + }, +}); + +export const Tasks = () => { + const { dagId } = useParams(); + const { + data, + error: TasksError, + isFetching, + isLoading, + } = useTaskServiceGetTasks({ + dagId: dagId ?? "", + }); + + // Only the latest dagrun id is needed with recent dag runs of 14 returned for filtering. + // This could be switched to the endpoint to get dag with only latest run once available. + const { data: runsData } = useDagsServiceRecentDagRuns( + { dagIdPattern: dagId ?? "" }, + undefined, + { + enabled: Boolean(dagId), + }, + ); + + const runs = + runsData?.dags.find((dagWithRuns) => dagWithRuns.dag_id === dagId) + ?.latest_dag_runs ?? []; + + // Fetch the latest dag run and get task instances since we only display last run + const { data: TaskInstancesResponse } = + useTaskInstanceServiceGetTaskInstances( + { + dagId: dagId ?? "", + dagRunId: runs[0]?.dag_run_id ?? "~", Review Comment: I am working on an API in another branch to filter by dag_id and optionally state to return the recent 14 task instances per task. Following is draft response and I will update this page and also runs page to use this that will be more efficient. Since this private ui endpoint this can be later updated as per needs without concern for backwards compatibility, ``` http :8000/ui/task_instances/recent_task_instances dag_id==example_complex state==failed ``` ```json { "task_instances": [ { "dag_id": "example_complex", "end_date": "2024-12-04T10:18:42.969547Z", "start_date": "2024-12-04T10:18:42.779151Z", "state": "failed", "task_id": "create_entry_gcs", "try_number": 1 }, ], "total_entries": 1 } ``` -- 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]
