Skip to content

Commit a18e7bd

Browse files
committed
Added content
1 parent 150b481 commit a18e7bd

5 files changed

+70
-61
lines changed

articles/iot-hub/how-to-schedule-broadcast-jobs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ zone_pivot_groups: iot-hub-howto-c2d-1
1616

1717
This article shows you how to create back-end app code to schedule and broadcast jobs.
1818

19-
Use Azure IoT Hub to schedule and track jobs that update up to millions of devices for the following:
19+
Use Azure IoT Hub to schedule and track jobs that update up to millions of devices for the following operations:
2020

2121
* Update desired properties
2222
* Update tags

includes/iot-hub-howto-schedule-broadcast-jobs-dotnet.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,37 +60,36 @@ jobClient = JobClient.CreateFromConnectionString(connString);
6060

6161
[!INCLUDE [iot-hub-howto-connect-service-iothub-entra-dotnet](iot-hub-howto-connect-service-iothub-entra-dotnet.md)]
6262

63-
### Create a direct method update job
63+
### Schedule a direct method update job
6464

65-
Use [ScheduleDeviceMethodAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to create a job to run a direct method on one or multiple devices.
65+
Use [ScheduleDeviceMethodAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to schedule a job to run a direct method on one or multiple devices.
6666

67-
This example schedules a job for a direct method method named "LockDoor" on one device named "Device-1". The device(s) included in the scheduled job are contained second parameter as a query condition.
67+
The [CloudToDeviceMethod](/dotnet/api/microsoft.azure.devices.cloudtodevicemethod.-ctor?#microsoft-azure-devices-cloudtodevicemethod-ctor(system-string-system-timespan-system-timespan)) object to specify the direct method name and device connection timeout values.
6868

6969
```csharp
70-
string methodJobId = Guid.NewGuid().ToString(); // a unique job ID
71-
static string deviceId = "Device-1"; // In this example, there is only one device affected.
72-
73-
// The CloudToDeviceMethod record specifies the direct method name and device connection timeout.
70+
// The CloudToDeviceMethod record specifies the direct method name and device connection timeout
7471
CloudToDeviceMethod directMethod =
7572
new CloudToDeviceMethod("LockDoor", TimeSpan.FromSeconds(5),
7673
TimeSpan.FromSeconds(5));
74+
```
75+
76+
This example schedules a job for a direct method method named "LockDoor" on one device named "Device-1". The device(s) included in the scheduled job are contained second parameter as a query condition.
7777

78+
```csharp
79+
string methodJobId = Guid.NewGuid().ToString(); // a unique job ID
80+
static string deviceId = "Device-1"; // In this example, there is only one device affected
7881
JobResponse result = await jobClient.ScheduleDeviceMethodAsync(methodJobId,
7982
$"DeviceId IN ['{deviceId}']",
8083
directMethod,
8184
DateTime.UtcNow,
8285
(long)TimeSpan.FromMinutes(2).TotalSeconds);
83-
84-
Console.WriteLine("Started Method Job");
8586
```
8687

8788
### Schedule a device desired twin update job
8889

89-
Use [ScheduleTwinUpdateAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to create a new desired twin update job to run on one or multiple devices.
90-
91-
First, create and populate a device `Twin` object for the update.
90+
Use [ScheduleTwinUpdateAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to schedule a new desired twin update job to run on one or multiple devices.
9291

93-
For example:
92+
First, create and populate a device `Twin` object for the update. For example:
9493

9594
```csharp
9695
static string deviceId = "Device-1";
@@ -103,7 +102,7 @@ twin.ETag = "*";
103102
twin.Properties.Desired["LocationUpdate"] = DateTime.UtcNow;
104103
```
105104

106-
Next, call `ScheduleTwinUpdateAsync`. Specify the devices to be updated in the second parameter.
105+
Next, call `ScheduleTwinUpdateAsync`. Specify the devices to be updated as a query in the second parameter.
107106

108107
```csharp
109108
string twinJobId = Guid.NewGuid().ToString();
@@ -118,9 +117,9 @@ JobResponse createJobResponse = jobClient.ScheduleTwinUpdateAsync(
118117

119118
### Monitor a job
120119

121-
Use [GetJobAsync](/dotnet/api/microsoft.azure.devices.jobclient.getjobasync?#microsoft-azure-devices-jobclient-getjobasync(system-string)) to monitor a job status.
120+
Use [GetJobAsync](/dotnet/api/microsoft.azure.devices.jobclient.getjobasync?#microsoft-azure-devices-jobclient-getjobasync(system-string)) to monitor the job status for a specific job ID.
122121

123-
This example checks the job status for a job ID periodically until the job is complete or failed.
122+
This example checks the job status for a job ID periodically until the job status is complete or failed. For example:
124123

125124
```csharp
126125
JobResponse result;

includes/iot-hub-howto-schedule-broadcast-jobs-java.md

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ ms.custom: mqtt, devx-track-java, devx-track-extended-java
1717

1818
This article describes how to use the [Azure IoT SDK for Java](https://github.com/Azure/azure-iot-sdk-java) to create backend service application code to schedule job to invoke a direct method or perform a device twin desired property update on one or more devices.
1919

20-
The [JobClient](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient) class contains methods that services can use to schedule jobs.
21-
2220
### Service import statements
2321

22+
The [JobClient](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient) class contains methods that services can use to schedule jobs.
23+
2424
Use the following service import statements to access the Azure IoT SDK for Java.
2525

2626
```java
@@ -67,18 +67,18 @@ JobClient jobClient = new JobClient(iotHubConnectionString);
6767

6868
[!INCLUDE [iot-hub-howto-connect-service-iothub-entra-java](iot-hub-howto-connect-service-iothub-entra-java.md)]
6969

70-
### Create a direct method update job
70+
### Schedule a direct method update job
7171

7272
Use [scheduleDeviceMethod](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-scheduledevicemethod(java-lang-string-java-lang-string-java-lang-string-java-lang-long-java-lang-long-java-lang-object-java-util-date-long)) to run a direct method on one or multiple devices.
7373

74-
This example method schedules a direct method call job for a specific job ID.
74+
This example method schedules a job for a direct method named "lockDoor" on a device named "Device-1".
7575

7676
```java
7777
// Schedule a job now to call the lockDoor direct method
7878
// against a single device. Response and connection
7979
// timeouts are set to 5 seconds.
8080
String deviceId = "Device-1";
81-
String jobId = "DMCMD" + UUID.randomUUID();
81+
String jobId = "DMCMD" + UUID.randomUUID(); //Job ID must be unique
8282

8383
// How long the job is permitted to run without
8484
// completing its work on the set of devices
@@ -100,21 +100,14 @@ try {
100100

101101
### Schedule a device twin update job
102102

103-
Use [scheduleUpdateTwin](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-scheduleupdatetwin(java-lang-string-java-lang-string-com-microsoft-azure-sdk-iot-service-devicetwin-devicetwindevice-java-util-date-long)) to create a new job to run a device twin update on one or multiple devices.
103+
Use [scheduleUpdateTwin](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-microsoft-azure-sdk-iot-service-jobs-jobclient-scheduleupdatetwin(java-lang-string-java-lang-string-com-microsoft-azure-sdk-iot-service-devicetwin-devicetwindevice-java-util-date-long)) to schedule a job to run a device twin update on one or multiple devices.
104104

105105
This example method schedules a device twin update job for a specific job Id.
106106

107-
First, prepare a `DeviceTwinDevice` record.
108-
109-
For example:
107+
First, prepare a `DeviceTwinDevice` record for the device twin update. For example:
110108

111109
```java
112110
String deviceId = "Device-1";
113-
String jobId = "DPCMD" + UUID.randomUUID();
114-
115-
// How long the job is permitted to run without
116-
// completing its work on the set of devices
117-
private static final long maxExecutionTimeInSeconds = 30;
118111

119112
//Create a device twin desired properties update object
120113
DeviceTwinDevice twin = new DeviceTwinDevice(deviceId);
@@ -126,9 +119,15 @@ twin.setDesiredProperties(desiredProperties);
126119
twin.setETag("*");
127120
```
128121

129-
Next, call `scheduleUpdateTwin` to schedule the update job.
122+
Then call `scheduleUpdateTwin` to schedule the update job. For example:
130123

131124
```java
125+
String jobId = "DPCMD" + UUID.randomUUID(); //Unique job ID
126+
127+
// How long the job is permitted to run without
128+
// completing its work on the set of devices
129+
private static final long maxExecutionTimeInSeconds = 30;
130+
132131
// Schedule the update twin job to run now for a single device
133132
System.out.println("Schedule job " + jobId + " for device " + deviceId);
134133
try {
@@ -150,33 +149,31 @@ Use [getJob](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient?#com-m
150149
For example:
151150

152151
```java
153-
private static void monitorJob(JobClient jobClient, String jobId) {
154-
try {
155-
JobResult jobResult = jobClient.getJob(jobId);
156-
if(jobResult == null)
157-
{
158-
System.out.println("No JobResult for: " + jobId);
159-
return;
160-
}
161-
// Check the job result until it's completed
162-
while(jobResult.getJobStatus() != JobStatus.completed)
163-
{
164-
Thread.sleep(100);
165-
jobResult = jobClient.getJob(jobId);
166-
System.out.println("Status " + jobResult.getJobStatus() + " for job " + jobId);
167-
}
168-
System.out.println("Final status " + jobResult.getJobStatus() + " for job " + jobId);
169-
} catch (Exception e) {
170-
System.out.println("Exception monitoring job: " + jobId);
171-
System.out.println(e.getMessage());
152+
try {
153+
JobResult jobResult = jobClient.getJob(jobId);
154+
if(jobResult == null)
155+
{
156+
System.out.println("No JobResult for: " + jobId);
172157
return;
173158
}
159+
// Check the job result until it's completed
160+
while(jobResult.getJobStatus() != JobStatus.completed)
161+
{
162+
Thread.sleep(100);
163+
jobResult = jobClient.getJob(jobId);
164+
System.out.println("Status " + jobResult.getJobStatus() + " for job " + jobId);
165+
}
166+
System.out.println("Final status " + jobResult.getJobStatus() + " for job " + jobId);
167+
} catch (Exception e) {
168+
System.out.println("Exception monitoring job: " + jobId);
169+
System.out.println(e.getMessage());
170+
return;
174171
}
175172
```
176173

177174
### Query a job status
178175

179-
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.
176+
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 the job status for one or more jobs.
180177

181178
For example:
182179

includes/iot-hub-howto-schedule-broadcast-jobs-node.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ var jobClient = JobClient.fromConnectionString(connectionString);
5959

6060
### Create a direct method update job
6161

62-
Use [scheduleDeviceMethod](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-scheduledevicemethod) to create a new direct method job to run a direct method on one or multiple devices.
62+
Use [scheduleDeviceMethod](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-scheduledevicemethod) to schedule a job to run a direct method on one or multiple devices.
6363

64-
First, create a direct method update variable.
64+
First, create a direct method update variable with method name, payload, and response timeout information. For example:
6565

6666
```javascript
6767
var methodParams = {
@@ -71,12 +71,14 @@ var methodParams = {
7171
};
7272
```
7373

74-
Call `scheduleDeviceMethod` to schedule the direct method call job:
74+
Then call `scheduleDeviceMethod` to schedule the direct method call job:
7575

7676
* Each job must have a unique job ID. You can use this job ID to monitor a job as described in the **Monitor a job** section of this article.
7777
* Specify a `queryCondition` parameter to evaluate which devices to run the job on.
7878
* Check the `jobResult` callback for the job schedule result. If the job was successfully scheduled, you can monitor the job status as shown in the **Monitor a job** section of this article.
7979

80+
For example:
81+
8082
```javascript
8183
var methodJobId = uuid.v4();
8284
var queryCondition = "deviceId IN ['myDeviceId']";
@@ -121,12 +123,14 @@ var twinPatch = {
121123
};
122124
```
123125

124-
Call `scheduleTwinUpdate` to schedule the device twin desired property update job:
126+
Then call `scheduleTwinUpdate` to schedule the device twin desired property update job:
125127

126128
* Each job must have a unique job ID. You can use this job ID to monitor a job as described in the **Monitor a job** section of this article.
127129
* Specify a `queryCondition` parameter to evaluate which devices to run the job on.
128130
* Check the `jobResult` callback for the job schedule result. If the job was successfully scheduled, you can monitor the job status as shown in the **Monitor a job** section of this article.
129131

132+
For example:
133+
130134
```javascript
131135
var twinJobId = uuid.v4();
132136
var queryCondition = "deviceId IN ['myDeviceId']";
@@ -156,7 +160,7 @@ jobClient.scheduleTwinUpdate(twinJobId,
156160

157161
### Monitor a job
158162

159-
Use [getJob](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-getjob) to monitor a job status for a specific job ID.
163+
Use [getJob](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-getjob) to monitor the job status for a specific job ID.
160164

161165
This example function checks the job status for a specific job ID periodically until the job is complete or failed.
162166

includes/iot-hub-howto-schedule-broadcast-jobs-python.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ The [IoTHubJobManager](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmanager)
3232
Add the following `import` statements.
3333

3434
```python
35+
import os
36+
import sys
37+
import datetime
38+
import time
39+
import threading
40+
import uuid
41+
import msrest
42+
3543
from azure.iot.hub import IoTHubJobManager
3644
from azure.iot.hub.models import JobProperties, JobRequest, Twin, TwinProperties, CloudToDeviceMethod
3745
```
@@ -64,24 +72,25 @@ iothub_job_manager = IoTHubJobManager.from_connection_string(IoTHubConnectionStr
6472

6573
[!INCLUDE [iot-hub-howto-connect-service-iothub-entra-python](iot-hub-howto-connect-service-iothub-entra-dotnet.md)]
6674

67-
### Create a direct method job
75+
### Schedule a direct method job
6876

69-
Use [create_scheduled_job](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmanager?#azure-iot-hub-iothubjobmanager-create-scheduled-job) to create a new direct method to run a direct method on one or multiple devices:
77+
Use [create_scheduled_job](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmanager?#azure-iot-hub-iothubjobmanager-create-scheduled-job) to schedule a new direct method to run a direct method on one or multiple devices:
7078

7179
`create_scheduled_job` parameter notes:
7280

7381
* `job_id` must be unique
7482
* Set `type` to `scheduleDeviceMethod`
7583
* Use `cloud_to_device_method` to set the direct method name and payload
7684
* Use `max_execution_time_in_seconds` to specify the execution time in seconds
77-
* Use `query_condition` to specify a condition for one or more devices that have the direct method call.
85+
* Use `query_condition` to specify the devices to be included for the direct method call
7886

7987
For example:
8088

8189
```python
8290
METHOD_NAME = "lockDoor"
8391
METHOD_PAYLOAD = "{\"lockTime\":\"10m\"}"
8492
job_id = uuid.uuid4()
93+
DEVICE_ID = "Device-1"
8594
TIMEOUT = 60
8695

8796
job_request = JobRequest()
@@ -105,7 +114,7 @@ Use [create_scheduled_job](/python/api/azure-iot-hub/azure.iot.hub.iothubjobmana
105114
* Set `type` to `scheduleUpdateTwin`
106115
* Use `update_twin` to set the direct method name and payload
107116
* Use `max_execution_time_in_seconds` to specify the execution time in seconds
108-
* Use `query_condition` to specify a condition for one or more devices that have the direct method call.
117+
* Use `query_condition` to specify a condition for one or more devices that have the direct method call
109118

110119
For example:
111120

0 commit comments

Comments
 (0)