Skip to content

Instantly share code, notes, and snippets.

@kazufusa
Created February 3, 2024 15:26
Show Gist options
  • Save kazufusa/2a9ca297e2cc01140d4fbc12eee5498c to your computer and use it in GitHub Desktop.
Save kazufusa/2a9ca297e2cc01140d4fbc12eee5498c to your computer and use it in GitHub Desktop.
Notify DAG timed out.
import logging
import time
from datetime import datetime, timedelta
from airflow.decorators import dag, task
def dag_timed_out_logging(context):
if context.get("reason") == "timed_out":
logging.error(f"""DAG timed out: {context.get("dag").safe_dag_id}""")
@dag(
start_date=datetime(2024, 1, 1),
catchup=False,
dagrun_timeout=timedelta(seconds=10),
on_failure_callback=dag_timed_out_logging,
)
def dagrun_timeout_example():
@task
def timeout_task():
logging.info("start")
time.sleep(30)
logging.info("end")
timeout_task()
dag_instance = dagrun_timeout_example()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment