amoghrajesh commented on code in PR #76833: URL: https://github.com/apache/airflow/pull/76833#discussion_r4612763573
########## airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/DurableBanner.tsx: ########## @@ -0,0 +1,147 @@ +/*! + * 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 { Box, HStack, Text, VStack } from "@chakra-ui/react"; +import { useTranslation } from "react-i18next"; + +import { useTaskStateStoreServiceGetTaskStateStore } from "openapi/queries"; +import type { TaskInstanceResponse, TaskInstanceState } from "openapi/requests"; + +import { Alert, Tooltip } from "src/system-components"; + +import { StateBadge } from "src/components/StateBadge"; +import Time from "src/components/Time"; + +import { useTaskInstanceCoordinates } from "src/hooks/useTaskInstanceCoordinates"; +import { isStatePending, useAutoRefresh } from "src/utils"; +import { renderDuration } from "src/utils/datetimeUtils"; + +// Written by ResumableJobMixin in the Task SDK, which also defines DurableDecision. +const DURABLE_RECORD_KEY = "__airflow_durable__"; + +export const DurableDecision = { + ALREADY_SUCCEEDED: "already_succeeded", + RECONNECTED: "reconnected", + RESUBMITTED: "resubmitted", + SUBMITTED: "submitted", +} as const; + +type DurableTry = { + readonly decision: (typeof DurableDecision)[keyof typeof DurableDecision]; + readonly external_id: unknown; + readonly saved_seconds: number | null; + readonly status?: TaskInstanceState | null; + readonly try_number: number | null; +}; + +type DurableRecord = { + readonly submitted_at?: string; + readonly tries?: Array<DurableTry>; +}; + +export const DurableBanner = ({ + taskInstance, + tryNumber, +}: { + readonly taskInstance?: Pick< + TaskInstanceResponse, + "dag_id" | "dag_run_id" | "map_index" | "state" | "task_id" + >; + readonly tryNumber?: number; +}) => { + const { t: translate } = useTranslation(["dag", "common"]); + const coordinates = useTaskInstanceCoordinates(); + const refetchInterval = useAutoRefresh({ dagId: taskInstance?.dag_id }); + + const { data } = useTaskStateStoreServiceGetTaskStateStore( + { + ...coordinates, + dagId: taskInstance?.dag_id ?? "", + dagRunId: taskInstance?.dag_run_id ?? "", + key: DURABLE_RECORD_KEY, + mapIndex: taskInstance?.map_index ?? -1, + taskId: taskInstance?.task_id ?? "", + }, + undefined, + { + // A first try never reconnects or reuses a result, so only retries can show the banner. + enabled: taskInstance !== undefined && (tryNumber ?? 0) > 1, + refetchInterval: isStatePending(taskInstance?.state) && refetchInterval, + // Most tasks are not durable, so the key is usually missing. + retry: false, + }, + ); + + const record = (data?.value ?? {}) as DurableRecord; Review Comment: Good idea, added a UI endpoint for this that returns a typed `DurableExecutionResponse`. The banner uses the generated hook, so the local types and the cast are gone. -- 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]
