amoghrajesh commented on code in PR #76833:
URL: https://github.com/apache/airflow/pull/76833#discussion_r4560330664


##########
airflow-core/src/airflow/ui/src/pages/TaskInstance/Logs/DurableBanner.tsx:
##########
@@ -0,0 +1,106 @@
+/*!
+ * 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 } from "@chakra-ui/react";
+import { useTranslation } from "react-i18next";
+
+import { useTaskStateStoreServiceGetTaskStateStore } from "openapi/queries";
+import type { TaskInstanceResponse } from "openapi/requests";
+
+import { Alert } from "src/system-components";
+
+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.
+const DURABLE_RECORD_KEY = "__airflow_durable__";
+
+type DurableTry = {
+  readonly decision: string;
+  readonly external_id: unknown;
+  readonly saved_seconds: number | null;
+  readonly try_number: number | null;
+};
+
+const DECISIONS_THAT_SAVE = new Set(["already_succeeded", "reconnected"]);
+
+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");
+  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,
+    {
+      enabled: taskInstance !== undefined,
+      refetchInterval: isStatePending(taskInstance?.state) && refetchInterval,
+      // Most tasks are not durable, so the key is usually missing.
+      retry: false,
+    },
+  );
+
+  const tries = (data?.value as { tries?: Array<DurableTry> } | 
undefined)?.tries ?? [];
+  const entry = tries.find(
+    (attempt) => attempt.try_number === tryNumber && 
DECISIONS_THAT_SAVE.has(attempt.decision),
+  );
+
+  if (entry === undefined) {
+    return undefined;
+  }
+
+  const seconds = entry.saved_seconds;
+  const externalId =
+    typeof entry.external_id === "string" ? entry.external_id : 
JSON.stringify(entry.external_id);
+  let detail = translate(`logs.durable.detail.${entry.decision}`, { id: 
externalId });
+
+  if (entry.decision === "reconnected") {
+    detail =
+      seconds === null
+        ? translate("logs.durable.detail.reconnectedRunning", { id: externalId 
})
+        : translate("logs.durable.detail.reconnected", {
+            duration: renderDuration(Math.round(seconds)),
+            id: externalId,

Review Comment:
   This ID is the external system's run (eg: a Databricks run), not an Airflow 
job. So all we store about it is the ID, its state, and when it was submitted 
and finished. Nothing like the Jobs table you screenshotted.
   
   Current version: the ID is replaced by a state badge ("Job: Running" / "Job: 
Success", same `StateBadge` as the Jobs page). The ID, submitted time and run 
time are in the tooltip. Screenshot below ( I personally dont think a badge 
fits well in a banner)
   
   Is that enough? A real job name (e.g. the Databricks job's name) has to come 
from each operator, which is a per provider hook. I'd rather do that in a 
follow-up with the run link Constance asked for earlier.
   
   <img width="3000" height="1800" 
alt="dbx_banner_reconnect_try2_running_tooltip" 
src="https://github.com/user-attachments/assets/63d9015f-f418-4bef-96a1-7d24ce82278b";
 />
   
   <img width="3000" height="1800" alt="dbx_banner_reconnect_try2_done_tooltip" 
src="https://github.com/user-attachments/assets/3f6ed3df-d076-4895-8d11-8a998d08d232";
 />
   
   
   
   



-- 
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]

Reply via email to