-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for templating on_failure_callback
#252
Conversation
on_failure_callback
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #252 +/- ##
==========================================
- Coverage 93.96% 93.95% -0.02%
==========================================
Files 8 8
Lines 630 645 +15
==========================================
+ Hits 592 606 +14
- Misses 38 39 +1 ☔ View full report in Codecov by Sentry. |
@tatiana, @pankajastro - should be all set to merge. Thanks! |
on_failure_callback
on_failure_callback
@jroach-astronomer and I connected to discuss this PR, and we decided to add an example in the README.md for this feature. We will include this in the 0.2.0 release. |
Updated to include documentation in the |
d84fa48
to
e17371e
Compare
Hey @jroach-astronomer, I'm wondering if you were able to test it. I tried to test this for Slack but got the below error Broken DAG: [/usr/local/airflow/dags/example_dag_factory.py]
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/airflow/utils/module_loading.py", line 42, in import_string
return getattr(module, class_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'airflow.providers.slack.notifications' has no attribute 'slack import send_slack_notification'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/astro/.local/lib/python3.12/site-packages/dagfactory/dagbuilder.py", line 842, in set_callback
on_state_callback_callable: Callable = import_string(on_state_callback_params["callback"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/airflow/utils/module_loading.py", line 44, in import_string
raise ImportError(f'Module "{module_path}" does not define a "{class_name}" attribute/class')
ImportError: Module "airflow.providers.slack.notifications" does not define a "slack import send_slack_notification" attribute/class
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/astro/.local/lib/python3.12/site-packages/dagfactory/dagfactory.py", line 158, in clean_dags
dags: Dict[str, Any] = self.build_dags()
^^^^^^^^^^^^^^^^^
File "/home/astro/.local/lib/python3.12/site-packages/dagfactory/dagfactory.py", line 112, in build_dags
raise DagFactoryException(f"Failed to generate dag {dag_name}. verify config is correct") from err
dagfactory.exceptions.DagFactoryException: Failed to generate dag example_dag. verify config is correct YAML default:
default_args:
owner: "default_owner"
start_date: 2018-03-01
end_date: 2018-03-05
retries: 1
retry_delay_sec: 300
#on_success_callback_name: print_hello_from_callback
#on_success_callback_file: $CONFIG_ROOT_DIR/print_hello.py
on_failure_callback:
callback: airflow.providers.slack.notifications.slack import send_slack_notification
text: |
:red_circle: Task Failed.
This task has failed and needs to be addressed.
Please remediate this issue ASAP.
concurrency: 1
max_active_runs: 1
dagrun_timeout_sec: 600
default_view: "tree"
orientation: "LR"
schedule_interval: "0 1 * * *"
on_failure_callback_name: print_hello_from_callback
on_failure_callback_file: $CONFIG_ROOT_DIR/print_hello.py
example_dag:
default_args:
owner: "custom_owner"
start_date: 2 days
description: "this is an example dag"
schedule_interval: "0 3 * * *"
render_template_as_native_obj: True
tasks:
task_1:
operator: airflow.operators.bash_operator.BashOperator
bash_command: "echo 1"
task_2:
operator: airflow.operators.bash_operator.BashOperator
bash_command: "echo 2"
dependencies: [task_1]
task_3:
operator: airflow.operators.python_operator.PythonOperator
python_callable_name: print_hello
python_callable_file: $CONFIG_ROOT_DIR/print_hello.py
dependencies: [task_1] Based on the example here: https://airflow.apache.org/docs/apache-airflow-providers-slack/stable/notifications/slackwebhook_notifier_howto_guide.html look like we may need to handle the notification import a bit differently or I'm doing something wrong it testing? |
@pankajastro, good catch, there is a typo in my example. It should be 'airflow.providers.slack.notifications.slack.send_slack_notification' for that callback. I will change that and push a new commit. |
Update pushed! |
I am getting the below error. Do you have yml which I can use for testing
|
We are moving this to the 0.21 milestone since @jroach-astronomer is on leave until after the next release. We can have pre-releases with this change as soon as the issue pointed out by @pankajastro is solved. |
@pankajastro, @tatiana, I've updated the |
@pankajastro, I've gone ahead and testing the changes using the Astro project in the Those 3 failing integration tests are due to the known symlink issue in Airflow 2.3.0. We'll need to resolve that in order for the integration tests to run. I'm also going to complete adding this callback functionality to all callbacks (at the DAG and Task-level, include success, retry, etc.). |
@pankajastro, @tatiana, wanted to check in on integration tests. Please see the comment above. Thanks! |
I think we can skip this particular test for Airflow 2.3.0 you may have to adjust a bit https://github.com/astronomer/dag-factory/blob/main/tests/test_example_dags.py |
Which Slack channel are you using to test this? We may need to configure it in CI. Has it already been configured? |
I'm able to test below YML DAG with slack webhook notification
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, we may need to fix failure CI!
…ned using file and name
43535c9
to
2bbe1ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @jroach-astronomer 🎉
Add support for templating in
on_failure_callback
. Requester is specifically looking to support templated parameters that do not need to be stored in a.py
file.Here's an example (from the issue submitted by @matveykortsev) for reference:
Closes: #209