AWS IoT
开发人员指南
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。请点击 Amazon AWS 入门,可查看中国地区的具体差异

任务事件

当任务待处理、已完成或已取消时,或者设备在执行任务时报告成功或失败,Jobs 会发布到 MQTT 协议上的预留主题。设备或管理和监控应用程序可以通过订阅这些主题来跟踪任务的状态。

任务已完成/已取消

当任务已完成或已取消时,AWS IoT Jobs 会在 MQTT 主题上发布消息:

  • $aws/events/job/jobID/completed

  • $aws/events/job/jobID/canceled

“已完成”消息包含以下示例负载:

{ "eventType": "JOB", "eventId": "7364ffd1-8b65-4824-85d5-6c14686c97c6", "timestamp": 1234567890, "operation": "completed", "jobId": "27450507-bf6f-4012-92af-bb8a1c8c4484", "status": "COMPLETED", "targetSelection": "SNAPSHOT|CONTINUOUS", "targets": [ "arn:aws:iot:us-east-1:123456789012:thing/a39f6f91-70cf-4bd2-a381-9c66df1a80d0", "arn:aws:iot:us-east-1:123456789012:thinggroup/2fc4c0a4-6e45-4525-a238-0fe8d3dd21bb" ], "description": "My Job Description", "completedAt": 1234567890123, "createdAt": 1234567890123, "lastUpdatedAt": 1234567890123, "jobProcessDetails": { "numberOfCanceledThings": 0, "numberOfRejectedThings": 0, "numberOfFailedThings": 0, "numberOfRemovedThings": 0, "numberOfSucceededThings": 3 } }

“已取消”消息包含以下示例负载:

{ "eventType": "JOB", "eventId": "568d2ade-2e9c-46e6-a115-18afa1286b06", "timestamp": 1234567890, "operation": "canceled", "jobId": "4d2a531a-da2e-47bb-8b9e-ff5adcd53ef0", "status": "CANCELED", "targetSelection": "SNAPSHOT|CONTINUOUS", "targets": [ "arn:aws:iot:us-east-1:123456789012:thing/Thing0-947b9c0c-ff10-4a80-b4b3-cd33d0145a0f", "arn:aws:iot:us-east-1:123456789012:thinggroup/ThingGroup1-95c644d5-1621-41a6-9aa5-ad2de581d18f" ], "description": "My job description", "createdAt": 1234567890123, "lastUpdatedAt": 1234567890123 }
任务执行最终状态

当设备将任务执行更新为最终状态时,AWS IoT Jobs 会发布消息:

  • $aws/events/jobExecution/jobID/succeeded

  • $aws/events/jobExecution/jobID/failed

  • $aws/events/jobExecution/jobID/rejected

  • $aws/events/jobExecution/jobID/canceled

  • $aws/events/jobExecution/jobID/removed

或者,您也可以使用以下命令订阅所有这些项:

  • $aws/events/jobExecution/jobID/#

消息包含以下示例负载:

{ "eventType": "JOB_EXECUTION", "eventId": "cca89fa5-8a7f-4ced-8c20-5e653afb3572", "timestamp": 1234567890, "operation": "succeeded|failed|rejected|canceled|removed", "jobId": "154b39e5-60b0-48a4-9b73-f6f8dd032d27", "thingArn": "arn:aws:iot:us-east-1:123456789012:myThing/6d639fbc-8f85-4a90-924d-a2867f8366a7", "status": "SUCCEEDED|FAILED|REJECTED|CANCELED|REMOVED", "statusDetails": { "key": "value" } }