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

任务事件

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

任务待处理

当某个事物的待处理任务执行列表中添加或删除了任务时,或者对列表中任务的顺序有更改时,AWS IoT Jobs 会在 MQTT 主题上发布消息:

  • $aws/things/thingName/jobs/notify

    消息包含以下示例负载:

    { "jobs" : { "JobExecutionState": [ JobExecutionSummary ... ], }, "timestamp": timestamp, }
  • $aws/things/thingName/jobs/notify-next

    消息包含以下示例负载:

    { "execution" : JobExecutionData, "timestamp": timestamp, }
任务已完成/已取消

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

  • $aws/events/job/jobID/completed

  • $aws/events/job/jobID/canceled

消息包含以下示例负载:

{ "eventType": "job", "eventId": "UUID", "timestamp": timestamp, "operation": "completed|canceled", "jobId": "043", "status": "COMPLETED|CANCELED", "targets": [ "arn:aws:iot:us-west-2:123456789012:thing/xxxxxx", "arn:aws:iot:us-west-2:123456789012:thing/yyyyyy", "arn:aws:iot:us-west-2:123456789012:thing/zzzzzz" ], "description": "sample description", "completedAt": "14889914167084", "createdAt": "14889025672199", "lastUpdatedAt": "14889734904359", "jobProcessDetails": { "numberOfCanceledThings": 1, "numberOfSucceededThings": 1, "numberOfRejectedThings": 0, "numberOfFailedThings": 1, "numberOfInProgressThings": 0, "numberOfRemovedThings": 0, "processingTargets": [ arn:aws:iot:us-east-1:123456789012:thing/thingOne, arn:aws:iot:us-east-1:123456789012:thing/thingTwo, arn:aws:iot:us-east-1:123456789012:thinggroup/thingThree ] } }
任务执行最终状态

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

  • $aws/events/jobExecution/jobID/succeeded

  • $aws/events/jobExecution/jobID/failed

  • $aws/events/jobExecution/jobID/rejected

  • $aws/events/jobExecution/jobID/canceled

消息包含以下示例负载:

{ "eventType": "jobExecution", "eventId": "UUID", "timestamp": "14889025672199", "operation": "succeeded|failed|rejected|canceled", "jobId": "031", "status": "SUCCESS|FAILED|REJECTED|CANCELED", "thingName": "myThing", }