Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var JobClient = require('azure-iothub').JobClient;
var connectionString = process.env.IOTHUB_CONNECTION_STRING;
var jobClient = JobClient.fromConnectionString(connectionString);
var query = jobClient.createQuery();
var onResults = function(err, results) {
if (err) {
console.error('Failed to fetch the results: ' + err.message);
} else {
// Do something with the results
results.forEach(function(job) {
console.log(JSON.stringify(job, null, 2));
});
if (query.hasMoreResults) {
query.next(onResults);
#!/usr/bin/env node
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var program = require('commander');
var serviceError = require('./common.js').serviceError;
var getSas = require('./common.js').getSas;
var JobClient = require('azure-iothub').JobClient;
var showDeprecationText = require('./common.js').showDeprecationText;
showDeprecationText('az iot hub job cancel');
program
.description('Cancel existing job')
.usage('[options] ')
.option('-l, --login ', 'use the connection string provided as argument to use to authenticate with your IoT Hub instance')
.parse(process.argv);
var jobId = program.args[0];
var sas = getSas(program.login);
var jobClient = JobClient.fromSharedAccessSignature(sas);
jobClient.cancelJob(jobId, function (err) {
if (err) {
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
"use strict";
var uuid = require('uuid');
var JobClient = require('azure-iothub').JobClient;
var connectionString = process.env.IOTHUB_CONNECTION_STRING;
var queryCondition = "deviceId IN ['', '']"; // example queryCondition = "deviceId IN ['MyDevice1', 'MyDevice2']"
// For a single device you can also set queryCondition as "deviceId = ''" . Example, "deviceId = 'MyDevice1'"
var startTime = new Date();
var maxExecutionTimeInSeconds = 3600;
var jobClient = JobClient.fromConnectionString(connectionString);
// Schedule a device method call.
var methodParams = {
methodName: 'methodName',
payload: null,
responseTimeoutInSeconds: 15 // set response timeout as 15 seconds
};
#!/usr/bin/env node
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var program = require('commander');
var prettyjson = require('prettyjson');
var serviceError = require('./common.js').serviceError;
var getSas = require('./common.js').getSas;
var JobClient = require('azure-iothub').JobClient;
var showDeprecationText = require('./common.js').showDeprecationText;
showDeprecationText('az iot hub job list');
program
.description('Query existing jobs')
.usage('[options] [job-type] [job-status]')
.option('-l, --login ', 'use the connection string provided as argument to use to authenticate with your IoT Hub instance')
.option('-r, --raw', 'use this flag to return raw output instead of pretty-printed output')
.parse(process.argv);
var jobType = program.args[0];
var jobStatus = program.args[1];
var sas = getSas(program.login);
var jobClient = JobClient.fromSharedAccessSignature(sas);
private async scheduleTwinUpdate(twinPatch, iotHubConnectionString: string, deviceIds: string[]): Promise {
let twinJobId = uuid.v4();
let jobClient = iothub.JobClient.fromConnectionString(iotHubConnectionString);
let queryCondition = this.generateQureyCondition(deviceIds);
let startTime = new Date();
let maxExecutionTimeInSeconds = 300;
await jobClient.scheduleTwinUpdate(twinJobId, queryCondition, twinPatch, startTime, maxExecutionTimeInSeconds);
return this.monitorJob(twinJobId, jobClient);
}
private async scheduleTwinUpdate(twinPatch, iotHubConnectionString: string, deviceIds: string[]): Promise {
let twinJobId = uuid.v4();
let jobClient = iothub.JobClient.fromConnectionString(iotHubConnectionString);
let queryCondition = this.generateQureyCondition(deviceIds);
let startTime = new Date();
let maxExecutionTimeInSeconds = 300;
await jobClient.scheduleTwinUpdate(twinJobId, queryCondition, twinPatch, startTime, maxExecutionTimeInSeconds);
return this.monitorJob(twinJobId, jobClient);
}