From 31f65d16220ff989c77f5a43181cd3afb9847296 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Mon, 4 Sep 2023 11:32:55 +0800 Subject: [PATCH] Bring back SHUTDOWN-related constants This should restore code compatibility to 2.6 and prior. Note that the constants would not appear in documentation since they are deprecated and not use in Airflow core anyway anymore. --- airflow/utils/state.py | 25 +++++++++++++++++++ .../www/views/test_views_cluster_activity.py | 2 ++ 2 files changed, 27 insertions(+) diff --git a/airflow/utils/state.py b/airflow/utils/state.py index 32219edb73424..10355dcaf0795 100644 --- a/airflow/utils/state.py +++ b/airflow/utils/state.py @@ -58,6 +58,14 @@ class TaskInstanceState(str, Enum): SKIPPED = "skipped" # Skipped by branching or some other mechanism DEFERRED = "deferred" # Deferrable operator waiting on a trigger + # Not used anymore, kept for compatibility. + # TODO: Remove in Airflow 3.0. + SHUTDOWN = "shutdown" + """The task instance is being shut down. + + :meta private: + """ + def __str__(self) -> str: return self.value @@ -100,6 +108,14 @@ class State: SKIPPED = TaskInstanceState.SKIPPED DEFERRED = TaskInstanceState.DEFERRED + # Not used anymore, kept for compatibility. + # TODO: Remove in Airflow 3.0. + SHUTDOWN = TaskInstanceState.SHUTDOWN + """The task instance is being shut down. + + :meta private: + """ + finished_dr_states: frozenset[DagRunState] = frozenset([DagRunState.SUCCESS, DagRunState.FAILED]) unfinished_dr_states: frozenset[DagRunState] = frozenset([DagRunState.QUEUED, DagRunState.RUNNING]) @@ -190,6 +206,15 @@ def color_fg(cls, state): A list of states indicating that a task or dag is a success state. """ + # Kept for compatibility. DO NOT USE. + # TODO: Remove in Airflow 3.0. + terminating_states = frozenset([TaskInstanceState.SHUTDOWN, TaskInstanceState.RESTARTING]) + """ + A list of states indicating that a task has been terminated. + + :meta private: + """ + adoptable_states = frozenset( [TaskInstanceState.QUEUED, TaskInstanceState.RUNNING, TaskInstanceState.RESTARTING] ) diff --git a/tests/www/views/test_views_cluster_activity.py b/tests/www/views/test_views_cluster_activity.py index 0c70ea1425e92..1825a1d680620 100644 --- a/tests/www/views/test_views_cluster_activity.py +++ b/tests/www/views/test_views_cluster_activity.py @@ -115,6 +115,7 @@ def test_historical_metrics_data(admin_client, session, time_machine): "restarting": 0, "running": 0, "scheduled": 0, + "shutdown": 0, "skipped": 0, "success": 2, "up_for_reschedule": 0, @@ -143,6 +144,7 @@ def test_historical_metrics_data_date_filters(admin_client, session): "restarting": 0, "running": 0, "scheduled": 0, + "shutdown": 0, "skipped": 0, "success": 0, "up_for_reschedule": 0,