Skip to content

Commit b054b09

Browse files
Merge pull request mendix#9111 from mendix/kk-snow-fixmerge
Review branch for a snowflake PR
2 parents d2dc6e2 + 9a671c3 commit b054b09

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

content/en/docs/appstore/use-content/platform-supported-content/modules/snowflake/mendix-data-loader.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,55 @@ For example, for a data source with the ID *40FJYP9D*, the resulting statement w
139139
CALL MENDIX_DATA_LOADER.MX_FUNCTIONS.RUN_INGESTION_JOB('40FJYP9D','');
140140
```
141141

142+
## 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+
CREATE DATABASE IF NOT EXISTS <db name>;
159+
160+
CREATE SCHEMA IF NOT <schema name>;
161+
162+
USE SCHEMA <schema name>;
163+
164+
CREATE OR REPLACE NOTIFICATION INTEGRATION <NOTIFICATION INTEGRATION name>
165+
TYPE = EMAIL
166+
ENABLED = TRUE
167+
ALLOWED_RECIPIENTS = ('<mail1@company.com>', '<mail2@company.com>', ...);
168+
169+
CREATE OR REPLACE ALERT <ALERT name>
170+
WAREHOUSE = <warehouse name>
171+
SCHEDULE = '<integer> MINUTE' -- Or use CRON e.g. 15 * * * * UTC
172+
IF (
173+
EXISTS (
174+
SELECT 1
175+
FROM SNOWFLAKE.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+
```
142191
## Verifying the Access Token
143192

144193
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

Comments
 (0)