amoghrajesh commented on code in PR #57215:
URL: https://github.com/apache/airflow/pull/57215#discussion_r2497429670
##########
airflow-core/src/airflow/models/callback.py:
##########
@@ -131,26 +136,49 @@ class Callback(Base):
trigger_id: Mapped[int] = mapped_column(Integer, ForeignKey("trigger.id"),
nullable=True)
trigger = relationship("Trigger", back_populates="callback", uselist=False)
- def __init__(self, priority_weight: int = 1):
+ def __init__(self, priority_weight: int = 1, prefix: str = "", **kwargs):
+ """
+ Initialize a Callback. This is the base class so it shouldn't usually
need to be initialized.
+
+ :param priority_weight: Priority for callback execution (higher value
-> higher priority)
+ :param prefix: Optional prefix for metric names
+ :param kwargs: Additional data emitted in metric tags
+ """
self.state = CallbackState.PENDING
self.priority_weight = priority_weight
+ self.data = kwargs # kwargs can be used to include additional info in
metric tags
+ if prefix:
+ self.data["prefix"] = prefix
def queue(self):
self.state = CallbackState.QUEUED
+ def get_metric_info(self, status: str, result: Any) -> dict:
Review Comment:
Post merge comment: Can we make the `status` take a `CallbackState` object
instead? This fails the tests in 3.11+ python and the reason for that is enum
-> str interpolation changes in python3.11+, as an example see this:
3.10:
```python
Python 3.10.15 (main, Oct 8 2024, 00:44:52) [Clang 18.1.8 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from enum import Enum
>>>
>>> class CallbackState(str, Enum):
... SUCCESS = "success"
... FAILURE = "failure"
...
>>> status = CallbackState.SUCCESS
>>>
>>> print("str(status):", str(status))
str(status): CallbackState.SUCCESS
>>> print("f-string:", f"{status}")
f-string: success
>>> print("Using .value:", f"{status.value}")
Using .value: success
```
3.13:
```python
(airflow) ➜ airflow git:(callback-tests) ✗ python
Python 3.13.3 (main, Apr 8 2025, 13:54:08) [Clang 17.0.0
(clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from enum import Enum
...
... class CallbackState(str, Enum):
... SUCCESS = "success"
... FAILURE = "failure"
...
... status = CallbackState.SUCCESS
...
... print("str(status):", str(status))
... print("f-string:", f"{status}")
... print("Using .value:", f"{status.value}")
...
str(status): CallbackState.SUCCESS
f-string: CallbackState.SUCCESS
Using .value: success
```
##########
airflow-core/src/airflow/models/callback.py:
##########
@@ -131,26 +136,49 @@ class Callback(Base):
trigger_id: Mapped[int] = mapped_column(Integer, ForeignKey("trigger.id"),
nullable=True)
trigger = relationship("Trigger", back_populates="callback", uselist=False)
- def __init__(self, priority_weight: int = 1):
+ def __init__(self, priority_weight: int = 1, prefix: str = "", **kwargs):
+ """
+ Initialize a Callback. This is the base class so it shouldn't usually
need to be initialized.
+
+ :param priority_weight: Priority for callback execution (higher value
-> higher priority)
+ :param prefix: Optional prefix for metric names
+ :param kwargs: Additional data emitted in metric tags
+ """
self.state = CallbackState.PENDING
self.priority_weight = priority_weight
+ self.data = kwargs # kwargs can be used to include additional info in
metric tags
+ if prefix:
+ self.data["prefix"] = prefix
def queue(self):
self.state = CallbackState.QUEUED
+ def get_metric_info(self, status: str, result: Any) -> dict:
Review Comment:
I have fixed it for the meanwhile this way:
https://github.com/apache/airflow/pull/57935
--
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]