How to use the azure-iothub.JobClient function in azure-iothub

To help you get started, we’ve selected a few azure-iothub examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-iot-sdk-node / service / samples / job_query.js View on Github external
// 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);
github Azure / iothub-explorer / iothub-explorer-cancel-job.js View on Github external
#!/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) {
github Azure / azure-iot-sdk-node / service / samples / schedule_job.js View on Github external
// 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 
};
github Azure / iothub-explorer / iothub-explorer-query-job.js View on Github external
#!/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);
github microsoft / vscode-azure-iot-toolkit / src / distributedTracingManager.ts View on Github external
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);
    }
github microsoft / vscode-azure-iot-toolkit / src / DistributedTracingManager.ts View on Github external
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);
    }