You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-schedule-broadcast-jobs-java.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,9 @@ private static JobResult scheduleJobSetDesiredProperties(JobClient jobClient, St
133
133
134
134
### Monitor a job
135
135
136
-
Use [getJob](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-getjob(java-lang-string)) to access job status.
136
+
Use [getJob](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-getjob(java-lang-string)) to access a job status.
Use [queryDeviceJob](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-querydevicejob(java-lang-string)) to query job status.
167
+
Use [queryDeviceJob](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-querydevicejob(java-lang-string)) to query a job status.
This article describes how to use the [Azure IoT SDK for Node.js](https://github.com/Azure/azure-iot-sdk-node) to create backend service application code for job scheduling.
19
+
20
+
### Install service SDK package
21
+
22
+
Run this command to install **azure-iothub** on your development machine:
23
+
24
+
```cmd/sh
25
+
npm install azure-iothub --save
26
+
```
27
+
28
+
The [JobClient](/javascript/api/azure-iothub/jobclient) class exposes all methods required to interact with job scheduling from a backend application.
29
+
30
+
### Connect to IoT hub
31
+
32
+
You can connect a backend service to IoT Hub using the following methods:
Use [fromConnectionString](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-fromconnectionstring) to connect to IoT hub.
42
+
43
+
In this article, you create a back-end service that schedules a job to invoke a direct method on a device, schedules a job to update the device twin, and monitors the progress of each job. To perform these operations, your service needs the **registry read** and **registry write permissions**. By default, every IoT hub is created with a shared access policy named **registryReadWrite** that grants these permissions.
44
+
45
+
For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
46
+
47
+
```javascript
48
+
'use strict';
49
+
var JobClient =require('azure-iothub').JobClient;
50
+
var connectionString ='{Shared access policy connection string}';
51
+
var jobClient =JobClient.fromConnectionString(connectionString);
Use [scheduleDeviceMethod](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-scheduledevicemethod) to create a new device method job to run a device method on one or multiple devices.
61
+
62
+
This example schedules a device method call job for a specific job ID.
63
+
64
+
```javascript
65
+
var methodParams = {
66
+
methodName:'lockDoor',
67
+
payload:null,
68
+
responseTimeoutInSeconds:15// Timeout after 15 seconds if device is unable to process method
69
+
};
70
+
71
+
var methodJobId =uuid.v4();
72
+
console.log('scheduling Device Method job with id: '+ methodJobId);
73
+
jobClient.scheduleDeviceMethod(methodJobId,
74
+
queryCondition,
75
+
methodParams,
76
+
startTime,
77
+
maxExecutionTimeInSeconds,
78
+
function(err) {
79
+
if (err) {
80
+
console.error('Could not schedule device method job: '+err.message);
81
+
} else {
82
+
monitorJob(methodJobId, function(err, result) {
83
+
if (err) {
84
+
console.error('Could not monitor device method job: '+err.message);
85
+
} else {
86
+
console.log(JSON.stringify(result, null, 2));
87
+
}
88
+
});
89
+
}
90
+
});
91
+
```
92
+
93
+
### Schedule a device twin update job
94
+
95
+
Use [scheduleTwinUpdate](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-scheduletwinupdate) to create a new job to run a device twin update on one or multiple devices.
96
+
97
+
```javascript
98
+
var twinPatch = {
99
+
etag:'*',
100
+
properties: {
101
+
desired: {
102
+
building:'43',
103
+
floor:3
104
+
}
105
+
}
106
+
};
107
+
108
+
var twinJobId =uuid.v4();
109
+
110
+
console.log('scheduling Twin Update job with id: '+ twinJobId);
111
+
jobClient.scheduleTwinUpdate(twinJobId,
112
+
queryCondition,
113
+
twinPatch,
114
+
startTime,
115
+
maxExecutionTimeInSeconds,
116
+
function(err) {
117
+
if (err) {
118
+
console.error('Could not schedule twin update job: '+err.message);
119
+
} else {
120
+
monitorJob(twinJobId, function(err, result) {
121
+
if (err) {
122
+
console.error('Could not monitor twin update job: '+err.message);
123
+
} else {
124
+
console.log(JSON.stringify(result, null, 2));
125
+
}
126
+
});
127
+
}
128
+
});
129
+
```
130
+
131
+
### Monitor a job
132
+
133
+
Use [getJob](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-getjob) to monitor a job status.
134
+
135
+
This example checks the job status for a specific job ID periodically until the job is complete or failed.
136
+
137
+
```javascript
138
+
functionmonitorJob (jobId, callback) {
139
+
var jobMonitorInterval =setInterval(function() {
140
+
jobClient.getJob(jobId, function(err, result) {
141
+
if (err) {
142
+
console.error('Could not get job status: '+err.message);
if (result.status==='completed'||result.status==='failed'||result.status==='cancelled') {
146
+
clearInterval(jobMonitorInterval);
147
+
callback(null, result);
148
+
}
149
+
}
150
+
});
151
+
}, 5000);
152
+
}
153
+
```
154
+
155
+
### SDK schedule job example
156
+
157
+
The Azure IoT SDK for Node.js provides a working sample of a service app that handles job scheduling tasks. For more information, see [Job client E2E test](https://github.com/Azure/azure-iot-sdk-node/blob/a85e280350a12954f46672761b0b516d08d374b5/e2etests/test/job_client.js)
Copy file name to clipboardExpand all lines: includes/iot-hub-howto-schedule-broadcast-jobs-python.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,8 @@ ms.date: 1/7/2025
11
11
ms.custom: mqtt, devx-track-python, py-fresh-zinc
12
12
---
13
13
14
+
* Python SDK - [Python version 3.7 or later](https://www.python.org/downloads/) is recommended. Make sure to use the 32-bit or 64-bit installation as required by your setup. When prompted during the installation, make sure to add Python to your platform-specific environment variable.
15
+
14
16
## Overview
15
17
16
18
This article describes how to use the [Azure IoT SDK for Python](https://github.com/Azure/azure-iot-sdk-python) to create backend service application code for job scheduling.
Use [create_scheduled_job](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmanager?#azure-iot-hub-iothubjobmanager-create-scheduled-job) to create a new job to run a device twin update on one or multiple devices.
90
92
91
-
This example schedules a device twin update job for a specific job Id.
93
+
This example schedules a device twin update job for a specific job ID.
Use [get_scheduled_job](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmanager?#azure-iot-hub-iothubjobmanager-get-scheduled-job) to retrieve the details of a scheduled job on an IoT Hub.
113
+
Use [get_scheduled_job](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmanager?#azure-iot-hub-iothubjobmanager-get-scheduled-job) to retrieve the details of a specific job on an IoT Hub.
112
114
113
-
For example:
115
+
This example checks the job status every five seconds until the job is complete.
The Azure IoT SDK for Python provides working samples of service apps that handle job scheduling tasks. For more information, see:
127
129
128
-
*[Invoke a device method](https://github.com/Azure/azure-iot-hub-python/blob/8c8f315e8b26c65c5517541a7838a20ef8ae668b/samples/iothub_job_manager_method_sample.py)
129
-
*[Update a device twin](https://github.com/Azure/azure-iot-hub-python/blob/8c8f315e8b26c65c5517541a7838a20ef8ae668b/samples/iothub_job_manager_twin_update_sample.py)
130
+
*[Schedule a device method job](https://github.com/Azure/azure-iot-hub-python/blob/8c8f315e8b26c65c5517541a7838a20ef8ae668b/samples/iothub_job_manager_method_sample.py)
131
+
*[Schedule a device twin update](https://github.com/Azure/azure-iot-hub-python/blob/8c8f315e8b26c65c5517541a7838a20ef8ae668b/samples/iothub_job_manager_twin_update_sample.py)
0 commit comments