SameerMesiah97 commented on code in PR #64751:
URL: https://github.com/apache/airflow/pull/64751#discussion_r3114518059
##########
task-sdk/src/airflow/sdk/definitions/deadline.py:
##########
@@ -340,3 +343,58 @@ def decorator(
return reference_class
return decorator
+
+
[email protected](frozen=True)
+class VariableInterval:
+ """
+ Interval backed by an Airflow Variable.
+
+ This allows DeadlineAlert intervals to be configured dynamically using
+ Airflow Variables. The variable value is interpreted as minutes and
+ converted into a ``timedelta``.
Review Comment:
> Should this be minutes? I could be wrong, but I feel like we usually
measure everything in seconds in Airflow.
I have no strong opinions either way but I chose minutes because the
publicly documented example DAGs for `DeadlineAlerts` use minutes for
timedelta. Please see the below:
```
from datetime import datetime, timedelta
from airflow.sdk import AsyncCallback, DAG, DeadlineAlert, DeadlineReference
from airflow.providers.slack.notifications.slack_webhook import
SlackWebhookNotifier
from airflow.providers.standard.operators.empty import EmptyOperator
with DAG(
dag_id="deadline_alert_example",
deadline=DeadlineAlert(
reference=DeadlineReference.DAGRUN_QUEUED_AT,
interval=timedelta(minutes=15),
callback=AsyncCallback(
SlackWebhookNotifier,
kwargs={
"text": "🚨 Dag {{ dag_run.dag_id }} missed deadline at {{
deadline.deadline_time }}. DagRun: {{ dag_run }}"
},
),
),
):
EmptyOperator(task_id="example_task")
```
Here is the link to the documentation:
https://airflow.apache.org/docs/apache-airflow/stable/howto/deadline-alerts.html
Of course, the downside is that we will be losing precision but my
understanding is that most users will not set SLAs at the second level as they
will be running batches that will run for several minutes at the very least.
--
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]