Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
김진영
airflow-test
Commits
329bc14c
Commit
329bc14c
authored
May 23, 2022
by
김진영
Browse files
Add new file
parent
27e59148
Changes
1
Hide whitespace changes
Inline
Side-by-side
fail_alert.py
0 → 100644
View file @
329bc14c
from
airflow.operators.bash
import
BashOperator
from
dateutil.relativedelta
import
relativedelta
def
fail_alert
(
context
):
context_data
=
"""
{
"@context": "https://schema.org/extensions",
"@type":"MessageCard",
"themeColor":"0072C6",
"title":"Batch Job Error",
"summary":"test",
"sections": [
{
"facts":[
{"name":"■ Exec Time", "value": "%s"},
{"name":"■ Task", "value": "%s"},
{"name":"■ DAG", "value": "%s"},
{"name":"■ Reason", "value": "%s"},
{"name":"■ Log URL", "value": "%s"},
]
}
]
}
"""
%
(
context
.
get
(
'execution_date'
)
+
relativedelta
(
hours
=
9
),
context
.
get
(
'task_instance'
).
task_id
,
context
.
get
(
'task_instance'
).
dag_id
,
context
.
get
(
'exception'
),
context
.
get
(
'task_instance'
).
log_url
.
replace
(
"localhost:8080"
,
Variable
.
get
(
"AIRFLOW_WEB_URL"
))
)
alert
=
BashOperator
(
task_id
=
'fail_alert'
,
bash_command
=
"curl -d
\'
{data}
\'
-H
\"
Content-Type: Application/JSON
\"
-X POST {teams_url}"
.
format
(
data
=
context_data
,
teams_url
=
Variable
.
get
(
"TEAMS_WEBHOOKS_URL"
)
)
)
return
alert
.
execute
(
context
=
context
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment