Skip to content

Commit

Permalink
add backcompat logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dstandish committed Dec 3, 2024
1 parent 39095d5 commit 8db9672
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion providers/src/airflow/providers/standard/sensors/time_delta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from time import sleep
from typing import TYPE_CHECKING, Any, NoReturn

from packaging.version import Version

from airflow import __version__ as airflow_version
from airflow.configuration import conf
from airflow.exceptions import AirflowSkipException
from airflow.providers.standard.triggers.temporal import DateTimeTrigger, TimeDeltaTrigger
Expand All @@ -31,6 +34,15 @@
if TYPE_CHECKING:
from airflow.utils.context import Context

AIRFLOW_V_2_11_PLUS = Version(Version(airflow_version).base_version) >= Version("2.11.0")
"""
Whether airflow version is 2.11 or greater.
todo: remove backcompat when min airflow version greater than 2.11
:meta private:
"""


class TimeDeltaSensor(BaseSensorOperator):
"""
Expand Down Expand Up @@ -91,10 +103,17 @@ def execute(self, context: Context) -> bool | NoReturn:
raise AirflowSkipException("Skipping due to soft_fail is set to True.") from e
raise

# todo: remove backcompat when min airflow version greater than 2.11
timeout: int | float | timedelta
if AIRFLOW_V_2_11_PLUS:
timeout = self.timeout
else:
timeout = timedelta(seconds=self.timeout)

self.defer(
trigger=trigger,
method_name="execute_complete",
timeout=self.timeout,
timeout=timeout,
)

def execute_complete(self, context: Context, event: Any = None) -> None:
Expand Down

0 comments on commit 8db9672

Please sign in to comment.