Configure a task to send success notifications

Snowflake 可以在任务图成功完成时,将成功通知推送到云消息传递服务。本主题提供有关使用云消息传递为任务配置成功通知支持的说明。

Success notification integration is only specified on a root task of a task graph. Snowflake only sends success notifications when the entire task graph is successfully executed and will not send notifications for any successfully executed standalone task, which is different from error notification integration.

Note

无服务器任务和用户管理任务(即依赖虚拟仓库提供计算资源的任务)都支持任务成功通知功能。

To enable a task to send success notifications, you must associate the task with a message notification integration. Follow the task documentation to create a notification integration with Amazon Web Services Simple Notification Service (AWS SNS), Microsoft Azure Event Grid, or Google Pub/Sub.

Create a new task or modify an existing task to send success notifications

You can associate the task with a notification integration when running the CREATE TASK command to create a new task, or running the ALTER TASK command to modify an existing task.

Note

要创建或修改可引用通知集成的任务,需要对通知集成拥有 USAGE 权限的角色。此外,角色必须分别拥有架构的 CREATE TASK 权限或任务的 OWNERSHIP 权限。

CREATE [ OR REPLACE ] TASK [ IF NOT EXISTS ] <name>
    WAREHOUSE = <string>
    [...]
    SUCCESS_INTEGRATION = <integration_name>
ALTER TASK <name> SET SUCCESS_INTEGRATION = <integration_name>;

其中:

SUCCESS_INTEGRATION = integration_name

Name of the notification integration created in one of AWS SNS, Microsoft Azure Event Grid, or Google Pub/Sub platform level notifications.

Display success notifications

You can run SHOW TASKS or DESCRIBE TASK to see task success notifications. Snowflake adds a new column, success_integration, to the output of SHOW TASKS and DESCRIBE TASK. This field displays null for all child tasks. This field displays the name of the graph-level success integration if the notification integration is specified on a root task, and null otherwise.

有效负载

成功消息的主体包括用于识别任务图的信息,例如 rootTaskName、rootTaskID、queryID 和 attemptNumber。以下是任务图成功通知的示例消息有效负载。

{"version":"1.0",
 "messageId":"3ff1eff0-7ad7-493c-9552-c0307087e0c6",
 "messageType":"GRAPH_SUCCEEDED",
 "timestamp":"2021-11-11T19:46:39.648Z",
 "accountName":"XY12345",
 "rootTaskName":"AWS_UTEN_DPO_DB.AWS_UTEN_SC.UTEN_AWS_TK1",
 "rootTaskId":"01a03962-2b57-889e-0000-000000000001",
 "messages": [{
              "runId":"2021-11-11T19:46:23.826Z",
              "scheduledTime":"2021-11-11T19:46:23.826Z",
              "queryStartTime":"2021-11-11T19:46:24.879Z",
              "graphCompletedTime":"2021-11-11T19:54:24.5591",
              "queryId":"01a03962-0300-0002-0000-0000000034d8",
              "attemptNumber":5
}]}

请注意,必须将字符串解析为 JSON 对象,才能处理有效负载中的值。