批量計算使用 MNS 來實現消息通知。您負責主題的創建、管理和訂閱,并在創建集群或提交作業時指定相關配置。批量計算會依據配置向指定的主題推送消息,您可在 MNS 控制臺配置 URL、隊列、郵件和短信四種方式獲取消息通知。
說明
支持的事件
目前批量計算支持兩類事件,您可以按需配置:
- 集群事件:
- 集群已刪除:
OnClusterDeleted
; - 實例已創建:
OnInstanceCreated
; - 實例已運行:
OnInstanceActive
;
- 集群已刪除:
- 作業事件:
- 作業等待中:
OnJobWaiting
; - 作業運行中:
OnJobRunning
; - 作業已停止:
OnJobStopped
; - 作業已結束:
OnJobFinished
; - 作業已失敗:
OnJobFailed
; - 任務等待中:
OnTaskWaiting
; - 任務運行中:
OnTaskRunning
; - 任務停止中:
OnTaskStopped
; - 任務已結束:
OnTaskFinished
; - 任務已失敗:
OnTaskFailed
; - 實例等待中:
OnInstanceWaiting
; - 實例運行中:
OnInstanceRunning
; - 實例已停止:
OnInstanceStopped
; - 實例已結束:
OnInstanceFinished
; - 實例已失?。?code>OnInstanceFailed;
- 優先級改變:
OnPriorityChange
。
- 作業等待中:
消息格式
適用于 OnClusterDeleted
。
{
"Category": "Cluster",
"ClusterId": "cls-hr2rbl6qt5gki7392b8001",
"ClusterName": "test-cluster",
"CreationTime": "2016-11-01T15:25:02.837728Z",
"State": "Deleted",
"Event": "OnClusterDeleted"
}
適用于 OnInstanceCreated
、OnInstanceActive
。
{
"Category": "Cluster",
"ClusterId": "cls-hr2rbl6qt5gki7392b8001",
"Group": "group1",
"InstanceId": "i-wz9c51g2s6zsrtnqi4fa",
"InnerIpAddress": "10.45.168.26",
"Hints": "",
"State": "Starting",
"CreationTime": "2016-11-01T15:25:02.837728Z",
"Event": "OnInstanceCreated"
}
適用于 OnJobWaiting
、OnJobRunning
、OnJobStopped
、OnJobFinished
、OnJobFailed
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"JobName": "test-job",
"Event": "OnJobWaiting",
"State": "Waiting",
"CreationTime": "2016-11-01T15:25:02.837728Z",
"StartTime": "2016-11-01T15:35:02.837728Z",
"EndTime": "2016-11-01T15:45:02.837728Z",
"Message": ""
}
適用于 OnTaskWaiting
、OnTaskRunning
、OnTaskStopped
、OnTaskFinished
、OnTaskFailed
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"Task": "Echo",
"Event": "OnTaskWaiting",
"State": "Waiting",
"StartTime": "2016-11-01T15:35:02.837728Z",
"EndTime": "2016-11-01T15:45:02.837728Z"
}
適用于 OnInstanceWaiting
、OnInstanceRunning
、OnInstanceStopped
、OnInstanceFinished
、OnInstanceFailed
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"Task": "Echo",
"InstanceId": "0",
"Event": "OnInstanceWaiting",
"State": "Waiting",
"StartTime": "2016-11-01T15:35:02.837728Z",
"EndTime": "2016-11-01T15:45:02.837728Z",
"RetryCount": "0",
"Progress": "0",
"StdoutRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stderr.job-0000000058184218000008150000000D.task.0",
"StderrRedirectPath": "oss://bucket/tests/a44c0ad8-a003-11e6-8f8e-fefec0a80e06/logs/stdout.job-0000000058184218000008150000000D.task.0",
"ExitCode": "0",
"ErrorCode": "",
"ErrorMessage": "",
"Detail": ""
}
適用于 OnPriorityChange
。
{
"Category": "Job",
"JobId": "job-0000000058524720000077E900007257",
"JobName": "test-job",
"Event": "OnPriorityChange",
"State": "Waiting",
"CreationTime": "2016-11-01T15:45:02.837728Z",
"StartTime": "2016-11-01T15:55:02.837728Z",
"EndTime": "2016-11-01T15:57:02.837728Z",
"Message": "",
"From": "10",
"To": "20"
}
使用
使用消息隊列必須同時指定 MNS 主題名稱 (Name)、MNS 私網 Endpoint (Endpoint) 和關注的事件 (Events)。
以下我們將展示通過 SDK 展示如何使用 MNS 消息隊列,其中 MNS 主題名稱為test
,MNS私網 Endpoint 為http://xxx.mns.cn-beijing.aliyuncs.com/
,關注的事件為OnClusterDeleted
、OnInstanceCreated
和OnInstanceActive
。
SDK
from batchcompute.resources import (
ClusterDescription, Notification, Topic
)
cluster_desc = ClusterDescription()
notification = Notification()
topic = Topic()
topic.Name = 'test'
topic.Endpoint = 'http://xxx.mns.cn-beijing.aliyuncs.com/'
topic.Events = ["OnClusterDeleted", "OnInstanceCreated", "OnInstanceActive"]
notification.Topic = topic
cluster_desc.Notification = notification
文檔內容是否對您有幫助?