Summary
BatchCompute (Batch) supports throwing of events generated in the jobs and compute environment in the form of Cloud Message Queue (CMQ). For example, when events such as job execution success/failure and compute environment node creation success/failure/exception occur, notifications and callbacks can be made possible through the topic subscription mechanism of CMQ.
How to Use
A compute environment listening event is used as an example below to demonstrate how to register a compute environment-related event in three steps.
1. Create a CMQ topic
2. Create a compute environment and associate the CMQ topic
Add a notifications field when submitting a job (SubmitJob) or creating a compute environment (Create) and specify the event_name of the event to be listened to. Multiple events can be specified.
"notifications": [
{
"event_configs": [
{
"event_name": "JobFailed" // Event name
},
{
"event_name": "JobSucceed",
"event_vars": [ // Custom event parameter
{
"name": "jobSucceed",
"value": "Success"
}
]
}
],
"topic_name": "job-message" // CMQ topic name
}
],
Currently, it is only supported to associate CMQ topics when creating a compute environment via API or CLI. Doing so in the console will be supported in the future.
event_vars: In addition to the fixed message generated by the event, custom parameters can be added.
topic_name: Name of the associated CMQ topic (Note: This is not the ID). All event messages will be delivered to this topic which will then forward the messages to all subscribers.
3. Set up a subscriber and test
Add a subscriber to the newly created topic in the CMQ Console. For quick and easy viewing, you can specify an existing message queue.
The message structure is as follows. If a message queue is specified as the subscriber, you can quickly view the messages sent to the topic by Batch in CMQ Console > Message Receiving where the message content requires Base64 processing. {
"Events": [{
"EventVersion": "1.0",
"EventTime": "2018-06-15T14:43:17Z",
"Region": "ap-guangzhou",
"Batch": {
"ComputeNodeId": "node-0iy7wxyo",
"EnvId": "env-ptoxdb1t",
"ComputeNodeState": "CREATED",
"Mem": 8,
"ResourceCreatedTime": "2018-06-15T14:43:18Z",
"EnvName": "batch-env",
"ComputeNodeInstanceId": "ins-9rikj9kw",
"Cpu": 4
},
"EventName": "COMPUTE_NODE_CREATED",
"EventVars": []
}]
}
Job-related Events
|
JOB_RUNNING | Job is running |
JOB_SUCCEED | Job succeeded |
JOB_FAILED | Job failed |
JOB_FAILED_INTERRUPTED | Job is interrupted due to failure |
TASK_RUNNING | Task is running |
TASK_SUCCEED | Task succeeded |
TASK_FAILED | Task failed |
TASK_FAILED_INTERRUPTED | Task is interrupted due to failure |
TASK_INSTANCE_RUNNING | Task instance is running |
TASK_INSTANCE_SUCCEED | Task instance succeeded |
TASK_INSTANCE_FAILED | Task instance failed |
TASK_INSTANCE_FAILED_INTERRUPTED | Task instance is interrupted due to failure |
Compute Environment-related Events
|
COMPUTE_ENV_CREATED | Compute environment created |
COMPUTE_ENV_DELETED | Compute environment deleted |
COMPUTE_NODE_CREATED | Compute node successfully created |
COMPUTE_NODE_CREATION_FAILED | Compute node creation failed |
COMPUTE_NODE_RUNNING | Compute node is running |
COMPUTE_NODE_ABNORMAL | Compute node is abnormal |
COMPUTE_NODE_DELETING | Deleting compute node |
Was this page helpful?