Device workflow
A device can handle jobs that it runs using either of the following ways.
-
Get the next job
-
When a device first comes online, it should subscribe to the device's
notify-next
topic. -
Call the DescribeJobExecution MQTT API with jobId
$next
to get the next job, its job document, and other details, including any state saved instatusDetails
. If the job document has a code file signature, you must verify the signature before proceeding with processing the job request. -
Call the UpdateJobExecution MQTT API to update the job status. Or, to combine this and the previous step in one call, the device can call StartNextPendingJobExecution.
-
(Optional) You can add a step timer by setting a value for
stepTimeoutInMinutes
when you call either UpdateJobExecution or StartNextPendingJobExecution. -
Perform the actions specified by the job document using the UpdateJobExecution MQTT API to report on the progress of the job.
-
Continue to monitor the job execution by calling the DescribeJobExecution MQTT API with this jobId. If the job execution is deleted, DescribeJobExecution returns a
ResourceNotFoundException
.The device should be able to recover to a valid state if the job execution is canceled or deleted while the device is running the job.
-
Call the UpdateJobExecution MQTT API when finished with the job to update the job status and report success or failure.
-
Because this job's execution status has been changed to a terminal state, the next job available for execution (if any) changes. The device is notified that the next pending job execution has changed. At this point, the device should continue as described in step 2.
If the device remains online, it continues to receive notifications of the next pending job execution. This includes its job execution data, when it completes a job or a new pending job execution is added. When this occurs, the device continues as described in step 2.
-
-
Select from available jobs
-
When a device first comes online, it should subscribe to the thing's
notify
topic. -
Call the GetPendingJobExecutions MQTT API to get a list of pending job executions.
-
If the list contains one or more job executions, select one.
-
Call the DescribeJobExecution MQTT API to get the job document and other details, including any state saved in
statusDetails
. -
Call the UpdateJobExecution MQTT API to update the job status. If the
includeJobDocument
field is set totrue
in this command, the device can skip the previous step and retrieve the job document at this point. -
Optionally, you can add a step timer by setting a value for
stepTimeoutInMinutes
when you call UpdateJobExecution. -
Perform the actions specified by the job document using the UpdateJobExecution MQTT API to report on the progress of the job.
-
Continue to monitor the job execution by calling the DescribeJobExecution MQTT API with this jobId. If the job execution is canceled or deleted while the device is running the job, the device should be able to recover to a valid state.
-
Call the UpdateJobExecution MQTT API when finished with the job to update the job status and to report success or failure.
If the device remains online, it is notified of all pending job executions when a new pending job execution becomes available. When this occurs, the device can continue as described in step 2.
-
If the device is unable to carry out the job, it should call the UpdateJobExecution MQTT API
to update the job status to REJECTED
.