Skip to content

Commit

Permalink
Merge pull request #307 from gitnnolabs/add_notification_email
Browse files Browse the repository at this point in the history
Adiciona um novo operador que irá enviar um e-mail após todos os passos do processamento excutado.
  • Loading branch information
gitnnolabs authored Nov 11, 2021
2 parents 5de1c48 + 4a108ac commit 1c3a8c0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion airflow/dags/sync_kernel_to_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from airflow.models import Variable
from airflow.operators.python_operator import PythonOperator, ShortCircuitOperator
from airflow.operators.dagrun_operator import TriggerDagRunOperator
from airflow.operators.email_operator import EmailOperator

from opac_schema.v1 import models

Expand All @@ -22,7 +23,15 @@
)
from common.hooks import mongo_connect, kernel_connect

email_notification_recipients = os.environ.get(
"EMAIL_NOTIFICATION_RECIPIENTS", None)

EMAIL_NOTIFICATION_RECIPIENTS = (
email_notification_recipients.split(",") if email_notification_recipients else []
)

failure_recipients = os.environ.get("EMIAL_ON_FAILURE_RECIPIENTS", None)

EMIAL_ON_FAILURE_RECIPIENTS = (
failure_recipients.split(",") if failure_recipients else []
)
Expand Down Expand Up @@ -915,6 +924,15 @@ def register_last_issues(ds, **kwargs):
dag=dag,
)

send_notification_email = EmailOperator(
task_id='send_notification_email',
to=EMAIL_NOTIFICATION_RECIPIENTS,
subject='Site atualizado',
html_content=""" <h3>Site <a href="https://www.scielo.br">https://www.scielo.br</a> atualizado.</h3> """,
mime_charset='utf-8',
dag=dag
)

trigger_check_website_dag_task = TriggerDagRunOperator(
task_id="trigger_check_website_dag_task",
trigger_dag_id="check_website",
Expand All @@ -939,4 +957,6 @@ def register_last_issues(ds, **kwargs):

register_last_issues_task << delete_documents_task

register_last_issues_task >> trigger_check_website_dag_task
send_notification_email << register_last_issues_task

send_notification_email >> trigger_check_website_dag_task

0 comments on commit 1c3a8c0

Please sign in to comment.