ibardarov-fms commented on issue #31687:
URL: https://github.com/apache/airflow/issues/31687#issuecomment-1576488357
Here it is
```
from datetime import datetime, timedelta
from airflow.operators.dummy_operator import DummyOperator
from airflow.providers.docker.operators.docker import DockerOperator
from airflow.timetables.trigger import CronTriggerTimetable
from airflow.utils.trigger_rule import TriggerRule
from airflow import DAG
# Equals to the source/target schema
client_name = "apache_airflow"
default_args = {
"owner": "insights",
"depends_on_past": False,
"email_on_failure": False,
"email_on_retry": False,
"retries": 1,
"retry_delay": timedelta(minutes=5),
}
def notify_on_dag_failure(context):
dag_run = context.get("dag_run")
client_name = context["params"]["client_name"]
dag_id = dag_run.dag_id
reason = context["reason"]
task_instances = dag_run.get_task_instances()
failed_ti = [ti for ti in task_instances if ti.state == State.FAILED]
failed_ti_ids = ", ".join([ti.task_id for ti in failed_ti])
message = card_json(
"fail",
f"Failed {client_name}",
f"{reason}: {failed_ti_ids}",
client_name,
dag_id,
)
print(message)
with DAG(
f"test_{client_name}",
schedule=CronTriggerTimetable("0 5 * * *", timezone="UTC"), #
https://crontab.guru/
default_args=default_args,
catchup=False,
tags=["insights", "dbt", "snowflake", client_name],
on_failure_callback=notify_on_dag_failure,
max_active_runs=1,
max_active_tasks=1,
default_view="grid",
start_date=datetime(2022, 2, 28),
params={
"client_name": client_name,
},
) as dag:
begin = DummyOperator(task_id="begin")
end = DummyOperator(task_id="end", trigger_rule=TriggerRule.NONE_FAILED)
standard_zone = DockerOperator(
dag=dag,
task_id="standard_zone",
pool="snowflake",
doc_md="documentation...",
command=["/hello"],
environment={},
image="hello-world",
api_version="auto",
auto_remove=True,
docker_conn_id="docker_default",
docker_url="unix://var/run/docker.sock",
network_mode="host",
tty=True,
mount_tmp_dir=False,
do_xcom_push=False,
force_pull=True,
retries=3,
max_retry_delay=timedelta(hours=4),
retry_delay=timedelta(minutes=5),
retry_exponential_backoff=True,
)
begin >> standard_zone >> end
```
--
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]