dheerajturaga commented on code in PR #73763:
URL: https://github.com/apache/airflow/pull/73763#discussion_r4139507157
##########
airflow-core/src/airflow/ui/public/i18n/locales/en/components.json:
##########
@@ -131,6 +130,17 @@
"hide": "Hide value",
"show": "Show value"
},
+ "pausedDag": {
+ "drain": "Drain",
+ "drainDescription": "Queued runs start, but no scheduled runs are created.
The Dag pauses again once they finish.",
Review Comment:
Agreed, switched to "unfinished runs" in all three descriptions, and the
count now says "N unfinished Dag runs will start or resume."
##########
airflow-core/src/airflow/ui/src/components/TriggerDag/TriggerDAGModal.tsx:
##########
@@ -139,12 +141,11 @@ const TriggerDAGModal = ({
{runMode === RunMode.SINGLE ? (
<TriggerDAGForm
- dagDisplayName={dagDisplayName}
dagId={dagId}
error={error}
hasSchedule={hasSchedule}
isPartitioned={isPartitioned}
- isPaused={isPaused}
+ isPaused={dag?.is_paused ?? isPaused}
Review Comment:
Removed the `isPaused` prop from `TriggerDAGModal` and `TriggerDAGButton`,
and from the three places that passed it. The modal now derives `isPaused` from
the Dag it fetches on open, next to `isBackfillable` and `hasSchedule`, so
there is only one source.
##########
airflow-core/src/airflow/ui/src/components/TriggerDag/PausedDagOptions.tsx:
##########
@@ -0,0 +1,116 @@
+/*!
+ * 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 { Text, VStack } from "@chakra-ui/react";
+import { useTranslation } from "react-i18next";
+
+import { useBackfillServiceListBackfillsUi, useDagRunServiceGetDagRuns } from
"openapi/queries";
+import type { DagRunType } from "openapi/requests/types.gen";
+
+import { Accordion, Alert, RadioCardItem, RadioCardRoot } from
"src/system-components";
+
+export type PausedDagAction = "drain" | "keepPaused" | "unpause";
Review Comment:
Moved `PausedDagAction` to `types.ts`.
##########
airflow-core/src/airflow/ui/src/components/TriggerDag/PausedDagOptions.tsx:
##########
@@ -0,0 +1,116 @@
+/*!
+ * 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 { Text, VStack } from "@chakra-ui/react";
+import { useTranslation } from "react-i18next";
+
+import { useBackfillServiceListBackfillsUi, useDagRunServiceGetDagRuns } from
"openapi/queries";
+import type { DagRunType } from "openapi/requests/types.gen";
+
+import { Accordion, Alert, RadioCardItem, RadioCardRoot } from
"src/system-components";
+
+export type PausedDagAction = "drain" | "keepPaused" | "unpause";
+
+const NON_BACKFILL_RUN_TYPES: Array<Exclude<DagRunType, "backfill">> = [
+ "scheduled",
+ "manual",
+ "operator_triggered",
+ "asset_triggered",
+ "asset_materialization",
+];
+
+type PausedDagOptionsProps = {
+ readonly dagId: string;
+ readonly onChange: (action: PausedDagAction) => void;
+ readonly value: PausedDagAction;
+};
+
+const PausedDagOptions = ({ dagId, onChange, value }: PausedDagOptionsProps)
=> {
+ const { t: translate } = useTranslation("components");
+ // Draining a paused Dag lets every unfinished run proceed, not only the one
being created. The
+ // cached count can predate runs that have since finished (e.g. the run of
an earlier drain), so
+ // it is refetched and only trusted once fetched for this form.
+ const { data: activeBackfills } = useBackfillServiceListBackfillsUi({
active: true, dagId }, undefined, {
+ enabled: value === "drain",
+ staleTime: 0,
+ });
+ // A paused backfill's runs do not start while it stays paused, draining or
not.
+ const isBackfillPaused = activeBackfills?.backfills.some((backfill) =>
backfill.is_paused) ?? false;
+ const { data: unfinishedRuns, isFetchedAfterMount } =
useDagRunServiceGetDagRuns(
+ {
+ dagId,
+ limit: 1,
+ runType: isBackfillPaused ? NON_BACKFILL_RUN_TYPES : undefined,
+ state: ["queued", "running"],
+ },
+ undefined,
+ { enabled: value === "drain", staleTime: 0 },
+ );
+ const unfinishedRunCount = isFetchedAfterMount ?
(unfinishedRuns?.total_entries ?? 0) : 0;
+
+ return (
+ <VStack alignItems="stretch" gap={2}>
+ <Accordion.Root collapsible data-testid="paused-dag-options" size="lg"
variant="enclosed">
+ <Accordion.Item value="pausedDag">
+ <Accordion.ItemTrigger cursor="button">
+ {translate("pausedDag.title")}
+ {/* The section starts collapsed, so keep the choice that will be
applied visible. */}
+ <Text color="fg.muted" fontSize="sm" fontWeight="normal">
+ {translate(`pausedDag.${value}`)}
+ </Text>
+ </Accordion.ItemTrigger>
+ <Accordion.ItemContent>
+ <RadioCardRoot
+ onChange={(event) => onChange((event.target as
HTMLInputElement).value as PausedDagAction)}
Review Comment:
Switched to `onValueChange`. The selected value is looked up in the option
list, so there's no cast.
--
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]