This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 7731255975 Refactor: Consolidate import datetime (#34110)
7731255975 is described below

commit 7731255975b9ac1c8cf7b2e363aaa8b9cbba80b8
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Wed Sep 6 06:34:28 2023 +0000

    Refactor: Consolidate import datetime (#34110)
    
    Co-authored-by: Hussein Awala <[email protected]>
---
 airflow/example_dags/example_latest_only.py                  | 6 +++---
 airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py | 6 ++----
 airflow/www/forms.py                                         | 4 ++--
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/airflow/example_dags/example_latest_only.py 
b/airflow/example_dags/example_latest_only.py
index 3dc4e9137e..52555660be 100644
--- a/airflow/example_dags/example_latest_only.py
+++ b/airflow/example_dags/example_latest_only.py
@@ -18,7 +18,7 @@
 """Example of the LatestOnlyOperator"""
 from __future__ import annotations
 
-import datetime as dt
+import datetime
 
 from airflow import DAG
 from airflow.operators.empty import EmptyOperator
@@ -26,8 +26,8 @@ from airflow.operators.latest_only import LatestOnlyOperator
 
 with DAG(
     dag_id="latest_only",
-    schedule=dt.timedelta(hours=4),
-    start_date=dt.datetime(2021, 1, 1),
+    schedule=datetime.timedelta(hours=4),
+    start_date=datetime.datetime(2021, 1, 1),
     catchup=False,
     tags=["example2", "example3"],
 ) as dag:
diff --git a/airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py 
b/airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py
index 95a629af52..4ddd523e34 100644
--- a/airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py
+++ b/airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py
@@ -21,7 +21,6 @@ import json
 import math
 import time
 import warnings
-from datetime import datetime as dt
 from typing import TYPE_CHECKING
 
 import pendulum
@@ -132,12 +131,11 @@ class PodLauncher(LoggingMixin):
         :return:
         """
         resp = self.run_pod_async(pod)
-        curr_time = dt.now()
+        start_time = time.monotonic()
         if resp.status.start_time is None:
             while self.pod_not_started(pod):
                 self.log.warning("Pod not yet started: %s", pod.metadata.name)
-                delta = dt.now() - curr_time
-                if delta.total_seconds() >= startup_timeout:
+                if time.monotonic() >= start_time + startup_timeout:
                     raise AirflowException("Pod took too long to start")
                 time.sleep(1)
 
diff --git a/airflow/www/forms.py b/airflow/www/forms.py
index 6955939473..9b31290451 100644
--- a/airflow/www/forms.py
+++ b/airflow/www/forms.py
@@ -17,9 +17,9 @@
 # under the License.
 from __future__ import annotations
 
+import datetime
 import json
 import operator
-from datetime import datetime as dt
 from typing import Iterator
 
 import pendulum
@@ -75,7 +75,7 @@ class DateTimeWithTimezoneField(Field):
             # Check if the datetime string is in the format without timezone, 
if so convert it to the
             # default timezone
             if len(date_str) == 19:
-                parsed_datetime = dt.strptime(date_str, "%Y-%m-%d %H:%M:%S")
+                parsed_datetime = datetime.datetime.strptime(date_str, 
"%Y-%m-%d %H:%M:%S")
                 default_timezone = self._get_default_timezone()
                 self.data = default_timezone.convert(parsed_datetime)
             else:

Reply via email to