Azure IoT Hub Scheduled Job Never Completes (Exceeds maxExecutionTimeInSeconds)

Matthew Farstad 5 Reputation points
2024-02-09T14:58:43.62+00:00

Here's a status readout of a currently scheduled job:

$: az iot hub job list --hub-name <hub>
[
 {
   "cloudToDeviceMethod": {
     "connectTimeoutInSeconds": 30,
     "methodName": "<method>",
     "payload": 30,
     "responseTimeoutInSeconds": 30
   },
   "createdTime": "2024-02-09T14:33:11.2905158Z",
   "endTime": "9999-12-30T23:59:59.9999999Z",
   "jobId": "000001",
   "maxExecutionTimeInSeconds": 3600,
   "queryCondition": "*",
   "startTime": "2024-02-09T14:33:11.2905158Z",
   "status": "running",
   "type": "scheduleDeviceMethod"
 }
]

It is currently nearly half an hour later and it is still running. Is there no way to forcefully exit this job? I'm trying to test direct methods. My clients are using MQTT and I'm not sure why their direct method is getting triggered. Everyone is connected to the same hub.

Azure IoT Hub
Azure IoT Hub
An Azure service that enables bidirectional communication between internet of things (IoT) devices and applications.
1,134 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 13,791 Reputation points
    2024-02-10T00:39:40.52+00:00

    Hi @Matthew Farstad Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    Is there no way to forcefully exit this job?

    You can use the command az iot hub job cancel --hub-name {iothub_name} --job-id {job_id} to cancel an existing job. To find more details about the command and the different parameters it can take, please refer to the documentation on az iot hub job

    I'm not sure why their direct method is getting triggered

    We would more information on how you have created the job to get a better understanding of this behavior. If you have used the CLI command az iot hub job create to create the job, validate the options you have added to the --query-condition parameter of the command. The parameter is used to target the devices on which the Direct method needs to be invoked. I suspect you might have skipped adding this parameter while you created the job. Consequently, the direct method matching the same name gets triggered on any device in your IoT Hub. This might explain the behavior you are observing.

    To target a specific device using the Azure CLI command, you can use the command similar to the following

    az iot hub job create --hub-name {HubName} --job-id {JobName} \
                          --job-type scheduleDeviceMethod \
                          --method-name {MethodName} --method-payload 'null' \
                          --query-condition "deviceId = '{DeviceName}'"
    

    Hope this helps! Please let us know if you have any additional questions or need further assistance on this issue in the comments below. We would glad to help you further.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.