vincbeck commented on code in PR #50677:
URL: https://github.com/apache/airflow/pull/50677#discussion_r2093561653
##########
airflow-core/src/airflow/models/deadline.py:
##########
@@ -123,7 +122,71 @@ class DeadlineReference(Enum):
dag.deadline.reference.evaluate_with(dag_id=dag.dag_id)
"""
+ # Available References.
+ #
+ # The value is the name of the method executed to fetch the datetime
+ # value for the given Reference. For example DAGRUN_LOGICAL_DATE =
"dagrun_logical_date"
+ # will execute dagrun_logical_date() to find the dagrun's logical date.
DAGRUN_LOGICAL_DATE = "dagrun_logical_date"
+ DAGRUN_QUEUED_AT = "dagrun_queued_at"
+ _CUSTOM_REFERENCE_BASE = "_custom_reference"
+
+ def __init__(self, value):
+ self._fixed_dt = None # Initialize the storage for fixed datetime
+ super().__init__()
+
+ @classmethod
+ def FIXED_DATETIME(cls, dt: datetime):
+ """
+ Calculate a reference based on a set datetime rather than fetching a
value from the database.
+
+ For example, you could set the Deadline for "tomorrow before 9AM" by
+ providing the appropriate datetime object."
+ """
+ instance = object.__new__(cls)
+ instance._value_ = "fixed_datetime"
+ instance._fixed_dt = dt
+ return instance
+
+ def evaluate_with(self, **kwargs):
+ """Call the method in the enum's value with the provided kwargs."""
+ if self._fixed_dt:
+ return self._fixed_dt
+ return getattr(self, self.value)(**kwargs)
Review Comment:
Oh it is a an enum! My bad :)
--
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]