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


##########
task-sdk/src/airflow/sdk/definitions/deadline_reference.py:
##########
@@ -0,0 +1,136 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from abc import ABC, abstractmethod
+from dataclasses import dataclass
+from datetime import datetime
+from typing import Any
+
+from airflow.models.deadline import _fetch_from_db
+from airflow.utils.log.logging_mixin import LoggingMixin
+
+
+class BaseDeadlineReference(LoggingMixin, ABC):
+    """Base class for all Deadline implementations."""
+
+    # Whether the evaluation requires conditions.
+    requires_conditions = True
+
+    # Set of required kwargs - subclasses should override this.
+    required_kwargs: set[str] = set()
+
+    def evaluate_with(self, **kwargs: Any) -> datetime:
+        """Validate the provided kwargs and evaluate this deadline with the 
given conditions."""
+        missing_kwargs = self.required_kwargs - set(kwargs.keys())
+        if missing_kwargs:
+            raise ValueError(f"Missing required parameters: {', 
'.join(missing_kwargs)}")
+
+        return self._evaluate_with(**kwargs)
+
+    @abstractmethod
+    def _evaluate_with(self, **kwargs: Any) -> datetime:
+        """Must be implemented by subclasses to perform the actual 
evaluation."""
+        raise NotImplementedError
+
+    def evaluate(self) -> datetime:
+        """Evaluate this deadline with no parameters."""
+        if self.requires_conditions:
+            raise AttributeError("This deadline requires additional 
conditions, use evaluate_with() instead.")
+        return self.evaluate_with()

Review Comment:
   Responding to your comment below about using "context" there, maybe for now 
I'll try just dropping `evaluate()` and leave `evaluate_with()` as it is 
(without "context") and see how we feel about that.
   



-- 
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