Skip to content

Commit

Permalink
Refactor: Consolidate import datetime (#34110)
Browse files Browse the repository at this point in the history
Co-authored-by: Hussein Awala <hussein@awala.fr>
  • Loading branch information
eumiro and hussein-awala committed Sep 6, 2023
1 parent 2f5777c commit 7731255
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions airflow/example_dags/example_latest_only.py
Expand Up @@ -18,16 +18,16 @@
"""Example of the LatestOnlyOperator"""
from __future__ import annotations

import datetime as dt
import datetime

from airflow import DAG
from airflow.operators.empty import EmptyOperator
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:
Expand Down
6 changes: 2 additions & 4 deletions airflow/providers/cncf/kubernetes/pod_launcher_deprecated.py
Expand Up @@ -21,7 +21,6 @@
import math
import time
import warnings
from datetime import datetime as dt
from typing import TYPE_CHECKING

import pendulum
Expand Down Expand Up @@ -132,12 +131,11 @@ def start_pod(self, pod: V1Pod, startup_timeout: int = 120):
: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)

Expand Down
4 changes: 2 additions & 2 deletions airflow/www/forms.py
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +75,7 @@ def process_formdata(self, valuelist):
# 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:
Expand Down

0 comments on commit 7731255

Please sign in to comment.