ramitkataria commented on code in PR #58248:
URL: https://github.com/apache/airflow/pull/58248#discussion_r2520740058


##########
airflow-core/src/airflow/models/deadline_alert.py:
##########
@@ -0,0 +1,101 @@
+# 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 datetime import datetime
+from typing import TYPE_CHECKING
+
+import uuid6
+from sqlalchemy import JSON, Float, ForeignKey, String, Text, select
+from sqlalchemy.orm import Mapped
+from sqlalchemy_utils import UUIDType
+
+from airflow._shared.timezones import timezone
+from airflow.models import Base
+from airflow.models.deadline import ReferenceModels
+from airflow.utils.session import NEW_SESSION, provide_session
+from airflow.utils.sqlalchemy import UtcDateTime, mapped_column
+
+if TYPE_CHECKING:
+    from sqlalchemy.orm import Session
+
+
+class DeadlineAlert(Base):
+    """Table containing DeadlineAlert properties."""
+
+    __tablename__ = "deadline_alert"
+
+    id: Mapped[str] = mapped_column(UUIDType(binary=False), primary_key=True, 
default=uuid6.uuid7)
+    created_at: Mapped[datetime] = mapped_column(UtcDateTime, nullable=False, 
default=timezone.utcnow)
+
+    serialized_dag_id: Mapped[str] = mapped_column(
+        UUIDType(binary=False), ForeignKey("serialized_dag.id"), nullable=False
+    )
+
+    name: Mapped[str | None] = mapped_column(String(250), nullable=True)
+    description: Mapped[str | None] = mapped_column(Text, nullable=True)
+    reference: Mapped[dict] = mapped_column(JSON, nullable=False)
+    interval: Mapped[float] = mapped_column(Float, nullable=False)
+    callback: Mapped[dict] = mapped_column(JSON, nullable=False)

Review Comment:
   We might want to call this callback_def for consistency with deadline and 
callback models



##########
airflow-core/src/airflow/models/deadline.py:
##########
@@ -127,8 +142,11 @@ def _determine_resource() -> tuple[str, str]:
         resource_type, resource_details = _determine_resource()
 
         return (
-            f"[{resource_type} Deadline] {resource_details} needed by "
-            f"{self.deadline_time} or run: {self.callback}"
+            f"[{resource_type} Deadline] "
+            f"created at {self.created_at}, "
+            f"{resource_details}, "
+            f"needed by {self.deadline_time} "
+            f"or run: {self.callback.path}({self.callback.kwargs or ''})"

Review Comment:
   The callback portion is now handled by its own `__repr__` so I think we 
should revert this line to `or run: {self.callback}`



##########
airflow-core/src/airflow/models/deadline.py:
##########
@@ -98,13 +104,21 @@ class Deadline(Base):
     )
     callback = relationship("Callback", uselist=False, cascade="all, 
delete-orphan", single_parent=True)
 
+    # The DeadlineAlert that generated this deadline
+    deadline_alert_id: Mapped[str | None] = mapped_column(
+        UUIDType(binary=False), ForeignKey("deadline_alert.id", ondelete="SET 
NULL"), nullable=True
+    )
+    deadline_alert: Mapped[DeadlineAlert | None] = 
relationship("DeadlineAlert")
+
     __table_args__ = (Index("deadline_missed_deadline_time_idx", missed, 
deadline_time, unique=False),)
 
     def __init__(
         self,
         deadline_time: datetime,
         callback: CallbackDefinitionProtocol,
         dagrun_id: int,
+        deadline_alert_id: str | None,
+        # TODO: can't we drop this and use self.dagrun.dag_id??

Review Comment:
   I added the dag_id param here because the constructor doesn't have access to 
the session so it cannot lookup relationships. Once we implement lazy 
initialization of callbacks, which requires this PR to be merged, we wouldn't 
need this here because we could do the `Callback.create_from_sdk_def()` call in 
the `handle_miss` method



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

Reply via email to