Skip to content

Commit b3db870

Browse files
Merge pull request mendix#9109 from strategicalliances/strategicalliances-MDL-MailNotification
Strategicalliances mdl mail notification
2 parents a26a6e0 + 240b077 commit b3db870

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,49 @@ 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 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+
CREATE DATABASE IF NOT EXISTS <db name>;
153+
154+
CREATE SCHEMA IF NOT <schema name>;
155+
156+
USE SCHEMA <schema name>;
157+
158+
CREATE OR REPLACE NOTIFICATION INTEGRATION <NOTIFICATION INTEGRATION name>
159+
TYPE = EMAIL
160+
ENABLED = TRUE
161+
ALLOWED_RECIPIENTS = ('<mail1@company.com>', '<mail2@company.com>', ...);
162+
163+
CREATE OR REPLACE ALERT <ALERT name>
164+
WAREHOUSE = <warehouse name>
165+
SCHEDULE = '<integer> MINUTE' -- Or use CRON e.g. 15 * * * * UTC
166+
IF (
167+
EXISTS (
168+
SELECT 1
169+
FROM SNOWFLAKE.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+
```
142185
## Verifying the Access Token
143186

144187
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)