优化
This commit is contained in:
+18
-20
@@ -3,30 +3,28 @@ from airflow.operators.python_operator import PythonOperator
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from goojia_utils import dingutils
|
from goojia_utils import dingutils
|
||||||
|
|
||||||
|
# def send_dingding_alert(context):
|
||||||
|
# print('监测到错误')
|
||||||
def send_dingding_alert(context):
|
# task_instance = context.get('task_instance')
|
||||||
print('监测到错误')
|
# url = task_instance.log_url.replace("http://localhost:8080", "https://airflow.fangjia.com")
|
||||||
task_instance = context.get('task_instance')
|
# message = f"【airflow】 任务{task_instance.task_id}错误,请点击{url}查看!"
|
||||||
url = task_instance.log_url.replace("http://localhost:8080", "https://airflow.fangjia.com")
|
# print(message)
|
||||||
message = f"【airflow】 任务{task_instance.task_id}错误,请点击{url}查看!"
|
# dingutils.send_text(message, "ae14f50045e9375c354940a2afb86f14e453bd1f08f78da0ba6e788d35bccec4")
|
||||||
print(message)
|
# print("success")
|
||||||
dingutils.send_text(message, "ae14f50045e9375c354940a2afb86f14e453bd1f08f78da0ba6e788d35bccec4")
|
#
|
||||||
print("success")
|
# def fail_task():
|
||||||
|
# raise ValueError("This task is designed to fail")
|
||||||
def fail_task():
|
#
|
||||||
raise ValueError("This task is designed to fail")
|
# default_args = {
|
||||||
|
# "owner": "airflow",
|
||||||
default_args = {
|
# "retries": 0,
|
||||||
"owner": "airflow",
|
# "on_failure_callback": send_dingding_alert, # 任务失败时触发钉钉告警
|
||||||
"retries": 0,
|
# }
|
||||||
"on_failure_callback": send_dingding_alert, # 任务失败时触发钉钉告警
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
dag = DAG(
|
dag = DAG(
|
||||||
'test_failure_notification',
|
'test_failure_notification',
|
||||||
default_args=default_args,
|
#default_args=default_args,
|
||||||
start_date=datetime(2025, 4, 22),
|
start_date=datetime(2025, 4, 22),
|
||||||
schedule_interval=None
|
schedule_interval=None
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user