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
This article describes how to use the [Azure IoT SDK for .NET](https://github.com/Azure/azure-iot-sdk-csharp/blob/main/readme.md) to create backend service application code for job scheduling.
18
+
This article describes how to use the [Azure IoT SDK for .NET](https://github.com/Azure/azure-iot-sdk-csharp/blob/main/readme.md) 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.
19
19
20
20
### Add service NuGet Package
21
21
@@ -46,7 +46,7 @@ You can connect a backend service to IoT Hub using the following methods:
46
46
47
47
Connect a backend application to a device using [CreateFromConnectionString](/dotnet/api/microsoft.azure.devices.jobclient.createfromconnectionstring).
48
48
49
-
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.
49
+
This article describes back-end code that can schedule a job to invoke a direct method, schedule a job to update a device twin, and monitors the progress of a job for one or more devices. 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.
50
50
51
51
For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
Use [ScheduleDeviceMethodAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to create a new device method to run a device method on one or multiple devices.
65
+
Use [ScheduleDeviceMethodAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to create a new direct method to run a direct method on one or multiple devices.
66
66
67
-
This example schedules a device method call job for a specific job ID.
67
+
This example schedules a job for a direct method method named "LockDoor".
68
68
69
69
```csharp
70
70
stringmethodJobId=Guid.NewGuid().ToString();
@@ -83,39 +83,43 @@ JobResponse result = await jobClient.ScheduleDeviceMethodAsync(methodJobId,
83
83
Console.WriteLine("Started Method Job");
84
84
```
85
85
86
-
### Schedule a device twin update job
86
+
### Schedule a device desired twin update job
87
87
88
-
Use [ScheduleTwinUpdateAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to create a new device twin update job to run a device twin update on one or multiple devices.
88
+
Use [ScheduleTwinUpdateAsync](/dotnet/api/microsoft.azure.devices.jobclient.scheduledevicemethodasync) to create a new desired twin update job to run on one or multiple devices.
89
89
90
-
This example schedules a device twin update job for a specific job ID.
90
+
First, create and populate a device `Twin` object for the update.
Use [GetJobAsync](/dotnet/api/microsoft.azure.devices.jobclient.getjobasync?#microsoft-azure-devices-jobclient-getjobasync(system-string)) to monitor a job status.
117
121
118
-
This example checks the job status for a specific 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 is complete or failed.
119
123
120
124
```csharp
121
125
JobResponseresult;
@@ -132,4 +136,4 @@ do
132
136
The Azure IoT SDK for .NET provides working samples of service apps that handle job scheduling tasks. For more information, see:
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 for job scheduling.
18
+
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.
19
19
20
20
The [JobClient](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient) class contains methods that services can use to schedule jobs.
21
21
@@ -52,82 +52,94 @@ You can connect a backend service to IoT Hub using the following methods:
52
52
53
53
Use a [JobClient](/java/api/com.microsoft.azure.sdk.iot.service.jobs.jobclient) constructor to create the connection to IoT hub. The `JobClient` object handles the communication with your IoT hub.
54
54
55
-
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.
55
+
This article describes back-end code that can schedule a job to invoke a direct method, schedule a job to update a device twin, and monitors the progress of a job for one or more devices. 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.
56
56
57
57
For more information about shared access policies, see [Control access to IoT Hub with shared access signatures](/azure/iot-hub/authenticate-authorize-sas).
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 device method on one or multiple devices.
72
+
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.
75
73
76
-
This example schedules a device method call job for a specific job ID.
74
+
This example method schedules a direct method call job for a specific job ID.
System.out.println("Exception scheduling direct method job: "+ jobId);
97
+
System.out.println(e.getMessage());
98
+
}
98
99
```
99
100
100
101
### Schedule a device twin update job
101
102
102
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
104
104
-
This example schedules a device twin update job for a specific job Id.
105
+
This example method schedules a device twin update job for a specific job Id.
The Azure IoT SDK for Java provides a working sample of a service app that handles job scheduling tasks. For more information, see [Job Client Sample](https://github.com/Azure/azure-iot-service-sdk-java/blob/main/service/iot-service-samples/job-client-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/JobClientSample.java)
200
+
The Azure IoT SDK for Java provides a working sample of a service app that handles job scheduling tasks. For more information, see [Job Client Sample](https://github.com/Azure/azure-iot-service-sdk-java/blob/main/service/iot-service-samples/job-client-sample/src/main/java/samples/com/microsoft/azure/sdk/iot/JobClientSample.java).
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.
18
+
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 to schedule job to invoke a direct method or perform a device twin desired property update on one or more devices.
19
19
20
20
### Install service SDK package
21
21
@@ -40,10 +40,12 @@ You can connect a backend service to IoT Hub using the following methods:
40
40
41
41
Use [fromConnectionString](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-fromconnectionstring) to connect to IoT hub.
42
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.
43
+
This article describes back-end code that can schedule a job to invoke a direct method, schedule a job to update a device twin, and monitors the progress of a job for one or more devices. 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
44
45
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
46
47
+
For example:
48
+
47
49
```javascript
48
50
'use strict';
49
51
var JobClient =require('azure-iothub').JobClient;
@@ -55,33 +57,44 @@ 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.
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.
61
63
62
-
This example schedules a device method call job for a specific job ID.
64
+
First, create a direct method update variable.
63
65
64
66
```javascript
65
67
var methodParams = {
66
68
methodName:'lockDoor',
67
69
payload:null,
68
70
responseTimeoutInSeconds:15// Timeout after 15 seconds if device is unable to process method
69
71
};
72
+
```
73
+
74
+
Call `scheduleDeviceMethod` to schedule the direct method call job:
70
75
76
+
* 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.
77
+
* Specify a `queryCondition` parameter to evaluate which devices to run the job on.
78
+
* 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.
79
+
80
+
```javascript
71
81
var methodJobId =uuid.v4();
72
-
console.log('scheduling Device Method job with id: '+ methodJobId);
82
+
var queryCondition ="deviceId IN ['myDeviceId']";
83
+
var startTime =newDate();
84
+
var maxExecutionTimeInSeconds =300;
85
+
73
86
jobClient.scheduleDeviceMethod(methodJobId,
74
87
queryCondition,
75
88
methodParams,
76
89
startTime,
77
90
maxExecutionTimeInSeconds,
78
91
function(err) {
79
92
if (err) {
80
-
console.error('Could not schedule device method job: '+err.message);
93
+
console.error('Could not schedule direct method job: '+err.message);
81
94
} else {
82
95
monitorJob(methodJobId, function(err, result) {
83
96
if (err) {
84
-
console.error('Could not monitor device method job: '+err.message);
97
+
console.error('Could not monitor direct method job: '+err.message);
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
109
110
+
First, create a device twin desired property update variable.
111
+
97
112
```javascript
98
113
var twinPatch = {
99
114
etag:'*',
@@ -104,7 +119,15 @@ var twinPatch = {
104
119
}
105
120
}
106
121
};
122
+
```
123
+
124
+
Call `scheduleTwinUpdate` to schedule the device twin desired property update job:
107
125
126
+
* 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.
127
+
* Specify a `queryCondition` parameter to evaluate which devices to run the job on.
128
+
* 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.
129
+
130
+
```javascript
108
131
var twinJobId =uuid.v4();
109
132
110
133
console.log('scheduling Twin Update job with id: '+ twinJobId);
Use [getJob](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-getjob) to monitor a job status.
156
+
Use [getJob](/javascript/api/azure-iothub/jobclient?#azure-iothub-jobclient-getjob) to monitor a job status for a specific job ID.
134
157
135
-
This example checks the job status for a specific job ID periodically until the job is complete or failed.
158
+
This example function checks the job status for a specific job ID periodically until the job is complete or failed.
136
159
137
160
```javascript
138
161
functionmonitorJob (jobId, callback) {
@@ -154,4 +177,4 @@ function monitorJob (jobId, callback) {
154
177
155
178
### SDK schedule job example
156
179
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)
180
+
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).
0 commit comments