ferruzzi commented on code in PR #50677:
URL: https://github.com/apache/airflow/pull/50677#discussion_r2098520059


##########
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)
+
+    def evaluate(self):
+        """Call evaluate_with() without any conditions, because it looks 
strange in use that way."""
+        return self.evaluate_with()

Review Comment:
   Any opinions on this?   I honestly only added it because 
`DeadlineReference.FIXED_DATETIME(tomorrow).evaluate_with()` looked awkward, 
but maybe it's a bad idea to add the extra method?  I feel like the `with()` 
implies something is required, but maybe I'm just overthinking it.



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to