You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Setting Up Mail Notification on Failed Task Execution
143
+
144
+
Snowflake provides build in alert/notification functionality. This "ALERT" object holds a condition that you can specify and use to check if tasks have failed and send notifications based on your conditional expression. To use this you need to create a ["NOTIFICATION INTEGRATION"](https://docs.snowflake.com/en/sql-reference/sql/create-notification-integration-email) and ["ALERT"]() using the NOTIFICATION INTEGRATION and system function ["SYSTEM$SEND_EMAIL"](https://docs.snowflake.com/en/sql-reference/stored-procedures/system_send_email).
145
+
For other options using external integrations for sending all sorts of notifications you can check out this [blog post](https://medium.com/snowflake/introduction-to-snowflakes-data-pipeline-alerts-notifications-9beac8d127cc).
146
+
147
+
### SQL to Setup Mail Notification
148
+
149
+
The following is a template you can execute in a worksheet after filling in the specifics:
150
+
151
+
```sql
152
+
CREATEDATABASEIF NOT EXISTS <db name>;
153
+
154
+
CREATESCHEMAIF NOT <schema name>;
155
+
156
+
USE SCHEMA <schema name>;
157
+
158
+
CREATE OR REPLACE NOTIFICATION INTEGRATION <NOTIFICATION INTEGRATION name>
SCHEDULE ='<integer> MINUTE'-- Or use CRON e.g. 15 * * * * UTC
166
+
IF (
167
+
EXISTS (
168
+
SELECT1
169
+
FROMSNOWFLAKE.ACCOUNT_USAGE.TASK_HISTORY
170
+
WHERE (STATE ='FAILED'OR STATE ='FAILED_AND_AUTO_SUSPENDED') AND NAME ='<task name>'
171
+
AND SCHEDULED_TIME >= CONVERT_TIMEZONE('UTC',DATEADD(MINUTE, -<integer>, CURRENT_TIMESTAMP()))
172
+
)
173
+
)
174
+
THEN CALL SYSTEM$SEND_EMAIL(
175
+
'<NOTIFICATION INTEGRATION name>',
176
+
('<mail1@company.com>', '<mail5@company.com>', ...) --Subset of ALLOWED_RECIPIENTS in NOTIFICATION INTEGRATION.
177
+
'<Mail subject>',
178
+
'<Mail Body>.'
179
+
);
180
+
181
+
ALTER ALERT <ALERT name> RESUME; -- The ALERT has STATE Suspended when created and is started by this statement
182
+
183
+
SHOW ALERTS;
184
+
```
142
185
## Verifying the Access Token
143
186
144
187
When using OAuth authentication with the Mendix Data Loader, it is crucial to verify the access token received by your Mendix application. This verification process ensures the token's authenticity and integrity, protecting your application from unauthorized access attempts.
0 commit comments