-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
208 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 15 additions & 22 deletions
37
01-batch-serving(airflow)/dags/05-python-operator-with-slack-noti.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,34 @@ | ||
# slack_notifier에 선언한 webhook 전송 함수를 활용하여 slack 알림을 제공하는 예제 | ||
# slack_notifier에 선언한 webhook 전송 함수를 활용해 slack 알림을 제공하는 예제 | ||
|
||
from airflow import DAG | ||
from airflow.operators.python import PythonOperator | ||
from datetime import datetime, timedelta | ||
from datetime import datetime | ||
|
||
from airflow.exceptions import AirflowFailException | ||
from utils.slack_notifier import task_fail_slack_alert, task_succ_slack_alert | ||
|
||
default_args = { | ||
'owner': 'kyle', | ||
'depends_on_past': False, | ||
'start_date': datetime(2024, 1, 1), | ||
'end_date': datetime(2024, 1, 4), | ||
'retires': 1, | ||
'retry_delay': timedelta(minutes=5), | ||
"owner": "kyle", | ||
"depends_on_past": False, # 이전 DAG의 Task 성공 여부에 따라서 현재 Task를 실행할지 말지가 결정. False는 과거 Task의 성공 여부와 상관없이 실행 | ||
"start_date": datetime(2024, 1, 1), | ||
"end_date": datetime(2024, 1, 4) | ||
} | ||
|
||
|
||
def _handle_job_error() -> None: | ||
raise AirflowFailException("Raise Exception.") | ||
|
||
|
||
with DAG( | ||
dag_id='python_dag_with_slack_webhook', | ||
dag_id="python_dag_with_slack_webhook", | ||
default_args=default_args, | ||
schedule_interval='30 0 * * *', | ||
tags=['my_dags'], | ||
catchup=False, | ||
on_failure_callback=task_fail_slack_alert, | ||
# on_success_callback=task_succ_slack_alert # 성공 알림 필요 시 추가 | ||
schedule_interval="30 0 * * * ", | ||
tags=["my_dags"], | ||
catchup=True, | ||
on_failure_callback=task_fail_slack_alert | ||
) as dag: | ||
execution_date = "{{ ds }}" | ||
|
||
|
||
send_slack_noti = PythonOperator( | ||
task_id='raise_exception_and_send_slack_noti', | ||
python_callable=_handle_job_error, | ||
op_args=[execution_date] | ||
task_id="raise_exception_and_send_slack_noti", | ||
python_callable=_handle_job_error | ||
) | ||
|
||
send_slack_noti | ||
send_slack_noti |
Oops, something went wrong.