{"id":369062,"date":"2024-05-21T03:55:30","date_gmt":"2024-05-21T03:55:30","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=369062"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=369062","title":{"rendered":"<span>\u0410\u043b\u0435\u0440\u0442\u0438\u043d\u0433 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u0435\u043d\u0438\u044f DAG`\u043e\u0432 Apache Airflow \u0432 Telegram \u0437\u0430 1 \u043c\u0438\u043d\u0443\u0442\u0443<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u043e\u043b\u043b\u0435\u0433\u0438, \u0437\u0434\u0430\u0440\u043e\u0432\u0430! \u0412\u0440\u044f\u0434 \u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u0430\u043b\u0438 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0441\u0440\u0430\u0437\u0443 \u043a \u0434\u0435\u043b\u0443.<\/p>\n<h2>Notifier<\/h2>\n<p>\u0412 Apache Airflow \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>BaseNotifier<\/code> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0432 Airflow \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445\u00a0 callback \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u041d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\n<p>JiraNotifier<\/p>\n<\/li>\n<li>\n<p>DiscordNotifier<\/p>\n<\/li>\n<li>\n<p>SlackNotofier<\/p>\n<\/li>\n<li>\n<p>SmtpNotifier<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0443\u0445\u043e\u0434\u044f\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 &#8212; <a href=\"https:\/\/airflow.apache.org\/docs\/apache-airflow-providers\/core-extensions\/notifications.html\" rel=\"noopener noreferrer nofollow\">https:\/\/airflow.apache.org\/docs\/apache-airflow-providers\/core-extensions\/notifications.html<\/a><\/p>\n<p>\u041d\u043e \u0432\u044b\u0448\u043b\u043e \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 Telegram, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 BaseNotifier, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 DAG`\u043e\u0432. \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 Telegram \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 python-telegram-bot.<\/p>\n<p><code>pip install python-telegram-bot==20.4<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c. \u0418 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 notify, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/p>\n<pre><code class=\"python\">from airflow.notifications.basenotifier import BaseNotifier from telegram import Bot import asyncio import os   class TelegramNotification(BaseNotifier):      @staticmethod     async def send_tg_notifier(notifier_message):          telegram_bot_token = os.environ.get(\"TELEGRAM_NOTIFIER_BOT_TOKEN\")         telegram_chat_id = os.environ.get(\"TELEGRAM_NOTIFIER_CHAT_ID\")          bot = Bot(token=telegram_bot_token)         await bot.sendMessage(chat_id=telegram_chat_id, text=notifier_message, parse_mode=\"Markdown\")      def notify(self, context):          task_id = context[\"ti\"].task_id         task_state = context[\"ti\"].state         task_log_url = context[\"ti\"].log_url         dag_name = context[\"ti\"].dag_id          message_template = (f\"Dag name: `{dag_name}` \\n\"                             f\"Task id: `{task_id}` \\n\"                             f\"Task State: `?{task_state}?` \\n\"                             f\"Task Log URL: `{task_log_url}` \\n\"                             )          asyncio.run(self.send_tg_notifier(notifier_message=message_template)) <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0431\u043e\u0442\u0430 \u0438 id \u0447\u0430\u0442\u0430 \u0432 Telegram \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u042f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0448\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>dag_name<\/p>\n<\/li>\n<li>\n<p>task_id<\/p>\n<\/li>\n<li>\n<p>task_state<\/p>\n<\/li>\n<li>\n<p>task_log_url<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0442 TaskInstance \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 &#8212; <a href=\"https:\/\/airflow.apache.org\/docs\/apache-airflow\/2.0.1\/_api\/airflow\/models\/taskinstance\/index.html\" rel=\"noopener noreferrer nofollow\">https:\/\/airflow.apache.org\/docs\/apache-airflow\/2.0.1\/_api\/airflow\/models\/taskinstance\/index.html<\/a><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043a\u0430\u043d\u0430\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 DAG \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043a\u043e\u0434\u0435 \u0445\u0430\u0440\u0434\u043a\u043e\u0436\u0443 \u043a\u0440\u0430\u0441\u043d\u044b\u0435 \u043a\u0440\u0443\u0436\u043a\u0438 (?)<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b Apache Airflow \u043c\u043e\u0433 \u0441\u0430\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0442\u044c \u043d\u0430\u0441 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0442\u043e \u043d\u0443\u0436\u043d\u043e\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c DAG`\u0438.<\/p>\n<p>\u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0441 \u041d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c:<\/p>\n<p><code>from Notifier.Notifier import TelegramNotification<\/code>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f <code>on_failure_callback<\/code><\/p>\n<pre><code class=\"python\">from airflow.providers.mysql.hooks.mysql import MySqlHook from airflow.operators.empty import EmptyOperator from airflow.decorators import dag, task from datetime import datetime from Notifier.Notifier import TelegramNotification import pendulum   @dag( default_args={'owner': 'airflow', 'on_failure_callback': TelegramNotification()}, schedule_interval=\"0 6 * * *\", start_date=pendulum.datetime(2023, 10, 10, tz=\"Europe\/Moscow\"), catchup=False, description='\u042d\u0442\u043e\u0442 DAG \u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435' ) <\/code><\/pre>\n<p>Apache Airflow \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 callback:<\/p>\n<ul>\n<li>\n<p>on_success_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u00a0\u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438  <\/p>\n<\/li>\n<li>\n<p>on_failure_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>on_execute_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>on_retry_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e \u0438 \u0433\u043e\u0442\u043e\u0432\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>sla_miss_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u0432\u043e\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u041d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u043c\u043e\u0433 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f chat id \u0438 bot token, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u043e\u0442\u0430 \u0438 \u043a\u0430\u043d\u0430\u043b\u0430. \u042d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>TELEGRAM_NOTIFIER_BOT_TOKEN<\/code> \u0438 <code>TELEGRAM_NOTIFIER_CHAT_ID<\/code><\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a Apache Airflow \u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e \u0432 K8S \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e community chart, \u0442\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u0447\u0430\u0440\u0442\u0435 helm.<\/p>\n<pre><code class=\"yaml\">existingSecret: &amp;basic airflow-secret  extraEnv:   - name: TELEGRAM_NOTIFIER_BOT_TOKEN     valueFrom:       secretKeyRef:         name: *basic         key: TELEGRAM_NOTIFIER_BOT_TOKEN   - name: TELEGRAM_NOTIFIER_CHAT_ID     valueFrom:       secretKeyRef:         name: *basic         key: TELEGRAM_NOTIFIER_CHAT_ID <\/code><\/pre>\n<p>\u0421\u0430\u043c\u0438 \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 secrets.yaml.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f DAG \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0432 Telegram \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/1df\/eb9\/262\/1dfeb9262b5eceeb2b8d7039bb5c7886.jpg\" alt=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435\" title=\"\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435\" width=\"583\" height=\"224\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1df\/eb9\/262\/1dfeb9262b5eceeb2b8d7039bb5c7886.jpg\" data-blurred=\"true\"\/><\/p>\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u043b\u0435 Task Log URL. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u043b\u043e\u0433 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u0412 \u0446\u0435\u043b\u043e\u043c \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 Telegram \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430, \u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043b\u043e\u0433\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0438 \u0432 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u043e.<\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0438\u043a\u0440\u043e-\u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0430\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f DAG Apache Airflow \u0432 \u0432\u0430\u0448 \u043a\u0430\u043d\u0430\u043b Telegram, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043c\u0435\u043b\u044c\u043a\u043e\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 Airflow, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a callback \u0438 Notifier, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e\u0442 \u043c\u0438\u043d\u0438-\u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u0435\u043b\u044c, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<hr\/>\n<p><em><u>\u0411\u043e\u0439\u0441\u044f \u0441\u0432\u043e\u0438\u0445 \u0436\u0435\u043b\u0430\u043d\u0438\u0439, \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u0431\u044b\u0432\u0430\u0442\u044c\u0441\u044f<\/u><\/em><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/795845\/\"> https:\/\/habr.com\/ru\/articles\/795845\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u043e\u043b\u043b\u0435\u0433\u0438, \u0437\u0434\u0430\u0440\u043e\u0432\u0430! \u0412\u0440\u044f\u0434 \u043b\u0438 \u0432\u044b \u043f\u043e\u043f\u0430\u043b\u0438 \u043d\u0430 \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0439 \u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u0441\u0440\u0430\u0437\u0443 \u043a \u0434\u0435\u043b\u0443.<\/p>\n<h2>Notifier<\/h2>\n<p>\u0412 Apache Airflow \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>BaseNotifier<\/code> , \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0432 Airflow \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445\u00a0 callback \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u041d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u044b:<\/p>\n<ul>\n<li>\n<p>JiraNotifier<\/p>\n<\/li>\n<li>\n<p>DiscordNotifier<\/p>\n<\/li>\n<li>\n<p>SlackNotofier<\/p>\n<\/li>\n<li>\n<p>SmtpNotifier<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044e \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0432 \u043a\u0430\u043a\u0443\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0443\u0445\u043e\u0434\u044f\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u043c\u043e\u0436\u043d\u043e \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 &#8212; <a href=\"https:\/\/airflow.apache.org\/docs\/apache-airflow-providers\/core-extensions\/notifications.html\" rel=\"noopener noreferrer nofollow\">https:\/\/airflow.apache.org\/docs\/apache-airflow-providers\/core-extensions\/notifications.html<\/a><\/p>\n<p>\u041d\u043e \u0432\u044b\u0448\u043b\u043e \u0442\u0430\u043a, \u0447\u0442\u043e \u043d\u0435\u0442 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u0432 Telegram, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u0443 \u0437\u0430\u0434\u0430\u0447\u0443.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 BaseNotifier, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 DAG`\u043e\u0432. \u0414\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 Telegram \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 python-telegram-bot.<\/p>\n<p><code>pip install python-telegram-bot==20.4<\/code><\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0435\u043c \u0441\u0430\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c. \u0418 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434 notify, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439<\/p>\n<pre><code class=\"python\">from airflow.notifications.basenotifier import BaseNotifier from telegram import Bot import asyncio import os   class TelegramNotification(BaseNotifier):      @staticmethod     async def send_tg_notifier(notifier_message):          telegram_bot_token = os.environ.get(\"TELEGRAM_NOTIFIER_BOT_TOKEN\")         telegram_chat_id = os.environ.get(\"TELEGRAM_NOTIFIER_CHAT_ID\")          bot = Bot(token=telegram_bot_token)         await bot.sendMessage(chat_id=telegram_chat_id, text=notifier_message, parse_mode=\"Markdown\")      def notify(self, context):          task_id = context[\"ti\"].task_id         task_state = context[\"ti\"].state         task_log_url = context[\"ti\"].log_url         dag_name = context[\"ti\"].dag_id          message_template = (f\"Dag name: `{dag_name}` \\n\"                             f\"Task id: `{task_id}` \\n\"                             f\"Task State: `?{task_state}?` \\n\"                             f\"Task Log URL: `{task_log_url}` \\n\"                             )          asyncio.run(self.send_tg_notifier(notifier_message=message_template)) <\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441 \u0442\u043e\u043a\u0435\u043d\u043e\u043c \u0431\u043e\u0442\u0430 \u0438 id \u0447\u0430\u0442\u0430 \u0432 Telegram \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>\u042f \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0448\u0430\u0431\u043b\u043e\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<ul>\n<li>\n<p>dag_name<\/p>\n<\/li>\n<li>\n<p>task_id<\/p>\n<\/li>\n<li>\n<p>task_state<\/p>\n<\/li>\n<li>\n<p>task_log_url<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u043e\u0442 TaskInstance \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 &#8212; <a href=\"https:\/\/airflow.apache.org\/docs\/apache-airflow\/2.0.1\/_api\/airflow\/models\/taskinstance\/index.html\" rel=\"noopener noreferrer nofollow\">https:\/\/airflow.apache.org\/docs\/apache-airflow\/2.0.1\/_api\/airflow\/models\/taskinstance\/index.html<\/a><\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 \u043a\u0430\u043d\u0430\u043b, \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 DAG \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e, \u043f\u043e \u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043a\u043e\u0434\u0435 \u0445\u0430\u0440\u0434\u043a\u043e\u0436\u0443 \u043a\u0440\u0430\u0441\u043d\u044b\u0435 \u043a\u0440\u0443\u0436\u043a\u0438 (?)<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b Apache Airflow \u043c\u043e\u0433 \u0441\u0430\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043b\u0430\u0441\u0441 \u0438 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u044f\u0442\u044c \u043d\u0430\u0441 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0430\u0445, \u0442\u043e \u043d\u0443\u0436\u043d\u043e\u043e \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c DAG`\u0438.<\/p>\n<p>\u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u0441 \u041d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u043c:<\/p>\n<p><code>from Notifier.Notifier import TelegramNotification<\/code>  <\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0438 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f <code>on_failure_callback<\/code><\/p>\n<pre><code class=\"python\">from airflow.providers.mysql.hooks.mysql import MySqlHook from airflow.operators.empty import EmptyOperator from airflow.decorators import dag, task from datetime import datetime from Notifier.Notifier import TelegramNotification import pendulum   @dag( default_args={'owner': 'airflow', 'on_failure_callback': TelegramNotification()}, schedule_interval=\"0 6 * * *\", start_date=pendulum.datetime(2023, 10, 10, tz=\"Europe\/Moscow\"), catchup=False, description='\u042d\u0442\u043e\u0442 DAG \u0434\u0435\u043b\u0430\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u044f\u0432\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0435' ) <\/code><\/pre>\n<p>Apache Airflow \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 callback:<\/p>\n<ul>\n<li>\n<p>on_success_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u00a0\u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0437\u0430\u0434\u0430\u0447\u0438  <\/p>\n<\/li>\n<li>\n<p>on_failure_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>on_execute_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>on_retry_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0430\u0441\u044c \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e \u0438 \u0433\u043e\u0442\u043e\u0432\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e<\/p>\n<\/li>\n<li>\n<p>sla_miss_callback  &#8212; \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0443\u0441\u043f\u0435\u0432\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u0432 \u0441\u0432\u043e\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u043a \u0432\u0440\u0435\u043c\u0435\u043d\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u041d\u043e\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0441\u043c\u043e\u0433 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f, \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f chat id \u0438 bot token, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0431\u043e\u0442\u0430 \u0438 \u043a\u0430\u043d\u0430\u043b\u0430. \u042d\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044f \u043f\u0435\u0440\u0435\u0434\u0430\u044e \u0447\u0435\u0440\u0435\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f <code>TELEGRAM_NOTIFIER_BOT_TOKEN<\/code> \u0438 <code>TELEGRAM_NOTIFIER_CHAT_ID<\/code><\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a Apache Airflow \u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e \u0432 K8S \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e community chart, \u0442\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u0447\u0430\u0440\u0442\u0435 helm.<\/p>\n<pre><code class=\"yaml\">existingSecret: &amp;basic airflow-secret  extraEnv:   - name: TELEGRAM_NOTIFIER_BOT_TOKEN     valueFrom:       secretKeyRef:         name: *basic         key: TELEGRAM_NOTIFIER_BOT_TOKEN   - name: TELEGRAM_NOTIFIER_CHAT_ID     valueFrom:       secretKeyRef:         name: *basic         key: TELEGRAM_NOTIFIER_CHAT_ID <\/code><\/pre>\n<p>\u0421\u0430\u043c\u0438 \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 secrets.yaml.<\/p>\n<h2>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/h2>\n<p>\u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f DAG \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439 \u0432 Telegram \u043a\u0430\u043d\u0430\u043b \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\">\n<div><figcaption>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435<\/figcaption><\/div>\n<\/figure>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u043e\u043b\u0435 Task Log URL. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u043d\u0430 \u043b\u043e\u0433 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435. \u0412 \u0446\u0435\u043b\u043e\u043c \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0438\u0442\u044c \u0435\u0433\u043e \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0432 Telegram \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u0442 \u0442\u0440\u0443\u0434\u0430, \u043d\u043e \u0447\u0430\u0441\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u043b\u043e\u0433\u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0438 \u0432 \u043c\u0435\u0441\u0441\u0435\u043d\u0434\u0436\u0435\u0440\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u043e.<\/p>\n<h2>\u0418\u0442\u043e\u0433<\/h2>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u0438\u043a\u0440\u043e-\u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0430\u043c \u0433\u043e\u0442\u043e\u0432\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043e\u0431 \u043e\u0448\u0438\u0431\u043a\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f DAG Apache Airflow \u0432 \u0432\u0430\u0448 \u043a\u0430\u043d\u0430\u043b Telegram, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043c\u0435\u043b\u044c\u043a\u043e\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043b \u043e \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 Airflow, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a callback \u0438 Notifier, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c.<\/p>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u0442\u043e\u0442 \u043c\u0438\u043d\u0438-\u0443\u0432\u0435\u0434\u043e\u043c\u0438\u0442\u0435\u043b\u044c, \u043d\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u0433\u043a\u043e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<hr\/>\n<p><em><u>\u0411\u043e\u0439\u0441\u044f \u0441\u0432\u043e\u0438\u0445 \u0436\u0435\u043b\u0430\u043d\u0438\u0439, \u043e\u043d\u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u0431\u044b\u0432\u0430\u0442\u044c\u0441\u044f<\/u><\/em><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/795845\/\"> https:\/\/habr.com\/ru\/articles\/795845\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-369062","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/369062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=369062"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/369062\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=369062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=369062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=369062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}