Created
February 3, 2024 15:26
-
-
Save kazufusa/2a9ca297e2cc01140d4fbc12eee5498c to your computer and use it in GitHub Desktop.
Notify DAG timed out.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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