Apprise 通知操作指南¶
简介¶
Apprise 通知器 (airflow.providers.apprise.notifications.apprise.AppriseNotifier
) 允许用户使用 DAG 级别和任务级别的各种 on_*_callbacks
将消息发送到多个服务。
示例代码:¶
from datetime import datetime
from airflow import DAG
from airflow.providers.standard.operators.bash import BashOperator
from airflow.providers.apprise.notifications.apprise import send_apprise_notification
from apprise import NotifyType
with DAG(
dag_id="apprise_notifier_testing",
schedule=None,
start_date=datetime(2024, 1, 1),
catchup=False,
on_success_callback=[
send_apprise_notification(body="The dag {{ dag.dag_id }} succeeded", notify_type=NotifyType.SUCCESS)
],
):
BashOperator(
task_id="mytask",
on_failure_callback=[
send_apprise_notification(body="The task {{ ti.task_id }} failed", notify_type=NotifyType.FAILURE)
],
bash_command="fail",
)