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 Notifications on Failed Task Execution
143
+
144
+
Snowflake provides a built-in functionality for alerts and notifications. This `ALERT` object lets you specify a conditional expression to check if tasks have failed and send notifications if required.
145
+
146
+
To use this functionality, perform the following steps:
147
+
148
+
1. Create a [notifcation integration email](https://docs.snowflake.com/en/sql-reference/sql/create-notification-integration-email).
149
+
2. Create an [ALERT](https://docs.snowflake.com/en/sql-reference/commands-alert) using the notification integration and the ["SYSTEM$SEND_EMAIL"](https://docs.snowflake.com/en/sql-reference/stored-procedures/system_send_email) system function.
150
+
151
+
For more information about using external integrations for sending all types of notifications, see [Introduction to Snowflake's data pipeline alerts & notifications](https://medium.com/snowflake/introduction-to-snowflakes-data-pipeline-alerts-notifications-9beac8d127cc).
152
+
153
+
### Sample SQL to Set up a Mail Notification
154
+
155
+
The following is a sample SQL template which you can customize with your data and execute in a worksheet:
156
+
157
+
```sql
158
+
CREATEDATABASEIF NOT EXISTS <db name>;
159
+
160
+
CREATESCHEMAIF NOT <schema name>;
161
+
162
+
USE SCHEMA <schema name>;
163
+
164
+
CREATE OR REPLACE NOTIFICATION INTEGRATION <NOTIFICATION INTEGRATION name>
SCHEDULE ='<integer> MINUTE'-- Or use CRON e.g. 15 * * * * UTC
172
+
IF (
173
+
EXISTS (
174
+
SELECT1
175
+
FROMSNOWFLAKE.ACCOUNT_USAGE.TASK_HISTORY
176
+
WHERE (STATE ='FAILED'OR STATE ='FAILED_AND_AUTO_SUSPENDED') AND NAME ='<task name>'
177
+
AND SCHEDULED_TIME >= CONVERT_TIMEZONE('UTC',DATEADD(MINUTE, -<integer>, CURRENT_TIMESTAMP()))
178
+
)
179
+
)
180
+
THEN CALL SYSTEM$SEND_EMAIL(
181
+
'<NOTIFICATION INTEGRATION name>',
182
+
('<mail1@company.com>', '<mail5@company.com>', ...) --Subset of ALLOWED_RECIPIENTS in NOTIFICATION INTEGRATION.
183
+
'<Mail subject>',
184
+
'<Mail Body>.'
185
+
);
186
+
187
+
ALTER ALERT <ALERT name> RESUME; -- The ALERT has STATE Suspended when created and is started by this statement
188
+
189
+
SHOW ALERTS;
190
+
```
142
191
## Verifying the Access Token
143
192
144
193
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