AWS IoT continuous jobs queued in reverse order

167 views Asked by At

I have an AWS IoT Thing Group which includes some in-progress continuous jobs. When a device is added to the thing group, I want the continuous jobs must be processed as the order they were posted. However, look like the job executions are queued into my device in reverse order where the newest job is pushed first and so on.

I tried to search somewhere mention about the order of AWS IoT continuous job executions queued on the device but found nothing.

I wonder if I missed any configurations when I created the continuous jobs or the reverse order is the behavior of AWS IoT.

2

There are 2 answers

1
Vu Truong On

@brushtakopo Thanks for your answer.

My AWS IoT thing group has 4 in-progress continuous jobs like this https://drive.google.com/file/d/1Lg4ndjcZ8Htd7YUqX7FIuIG8erNkvE2O/view

You can see the jobs creation order older to newer is e_2c2df204-6d7e-44e7-9257-c2e705ec6b90 --> e_7e432f0a-41c4-4a2b-9e45-8debaca7ef90 --> e_3ca6819b-7bdb-4ad4-8c0c-6e00bb24774e --> e_b5406181-56cc-4d12-b043-586c4b06e0a4.

In my device, I subscribe the topic $aws/things/thingName/jobs/notify-next. When I add this device to the thing group, the notify-next messages are fetched as order below (bottom one is fetched first).

{
  "topicFilter": "$aws/things/thingName/jobs/notify-next",
  "qos": 0,
  "messages": [
    {
      "format": "json",
      "topic": "$aws/things/thingName/jobs/notify-next",
      "timestamp": 1677833217213,
      "payload": {
        "timestamp": {
          "isLosslessNumber": true,
          "value": "1677833217"
        },
        "execution": {
          "jobId": "e_2c2df204-6d7e-44e7-9257-c2e705ec6b90",
          "status": "QUEUED",
          "queuedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "lastUpdatedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "versionNumber": {
            "isLosslessNumber": true,
            "value": "1"
          },
          "executionNumber": {
            "isLosslessNumber": true,
            "value": "12"
          },
          "jobDocument": {
            "operation": "timezone",
            "timezone": "Australia/Perth"
          }
        }
      },
      "qos": 0
    },
    {
      "format": "json",
      "topic": "$aws/things/thingName/jobs/notify-next",
      "timestamp": 1677833173224,
      "payload": {
        "timestamp": {
          "isLosslessNumber": true,
          "value": "1677833173"
        },
        "execution": {
          "jobId": "e_7e432f0a-41c4-4a2b-9e45-8debaca7ef90",
          "status": "QUEUED",
          "queuedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "lastUpdatedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "versionNumber": {
            "isLosslessNumber": true,
            "value": "1"
          },
          "executionNumber": {
            "isLosslessNumber": true,
            "value": "12"
          }
        }
      },
      "qos": 0
    },
    {
      "format": "json",
      "topic": "$aws/things/thingName/jobs/notify-next",
      "timestamp": 1677832889195,
      "payload": {
        "timestamp": {
          "isLosslessNumber": true,
          "value": "1677832889"
        },
        "execution": {
          "jobId": "e_3ca6819b-7bdb-4ad4-8c0c-6e00bb24774e",
          "status": "QUEUED",
          "queuedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "lastUpdatedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "versionNumber": {
            "isLosslessNumber": true,
            "value": "1"
          },
          "executionNumber": {
            "isLosslessNumber": true,
            "value": "12"
          }
        }
      },
      "qos": 0
    },
    {
      "format": "json",
      "topic": "$aws/things/thingName/jobs/notify-next",
      "timestamp": 1677832788132,
      "payload": {
        "timestamp": {
          "isLosslessNumber": true,
          "value": "1677832788"
        },
        "execution": {
          "jobId": "e_b5406181-56cc-4d12-b043-586c4b06e0a4",
          "status": "QUEUED",
          "queuedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "lastUpdatedAt": {
            "isLosslessNumber": true,
            "value": "1677832788"
          },
          "versionNumber": {
            "isLosslessNumber": true,
            "value": "1"
          },
          "executionNumber": {
            "isLosslessNumber": true,
            "value": "12"
          }
        }
      },
      "qos": 0
    }
  ]
}

Can I have the notify-next is fired as order that I created the continuous jobs?

I don't think subscribe notify could help because it sends 4 jobs at a time that I don't know the order.

Thanks!

0
brushtakopo On

Without any code it is difficult to understand which MQTT topic you are using to get the list of jobs or how you are starting a job. Ideally, you should follow the device flow as described here. One important API is the StartNextPendingJobExecution. As mentioned, Job executions are returned in the order in which they were created.. So calling this API should give you the job to execute in the right order.