How to use the azure-iothub.JobClient.fromConnectionString 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 / 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 ['<device Id 1>', '<device Id 2>']"; // example queryCondition = "deviceId IN ['MyDevice1', 'MyDevice2']"
// For a single device you can also set queryCondition as "deviceId = '<device id>'" . 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 
};

var methodJobId = uuid.v4();
console.log('scheduling Device Method job with id: ' + methodJobId);
jobClient.scheduleDeviceMethod(methodJobId,
                               queryCondition,
                               methodParams,
                               startTime,
                               maxExecutionTimeInSeconds,
                               function(err) {
github Azure / azure-iot-sdk-node / ts-e2e / src / job_client.tests.ts View on Github external
it('schedules a twin update job with a sql query and succeeds', (testCallback) => {
      const jobClient = JobClient.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING);
      const testJobId = uuid.v4();
      const testTwinPatch = {
        etag: '*',
        tags: {
          key: 'value2'
        },
        properties: { desired: {}, reported: {} }
      };

      debug('scheduling a twin update job with a sql query with the id: ' + testJobId);
      debug('Query: ' + 'deviceId = \'' + testDeviceId + '\'');
      jobClient.scheduleTwinUpdate(testJobId, 'deviceId = \'' + testDeviceId + '\'', testTwinPatch, new Date(Date.now()), 120, continueWith(() => {
        waitForJobStatus(jobClient, testJobId, 'completed', continueWith(() => {
          const registry = Registry.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING);
          registry.getTwin(testDeviceId, continueWith((twin) => {
            assert.equal(twin.tags.key, testTwinPatch.tags.key);
github Azure / azure-iot-sdk-node / ts-e2e / src / job_client.tests.ts View on Github external
it('schedules a device method job with a sql query and succeeds', (testCallback) => {
      const jobClient = JobClient.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING);
      const testJobId = uuid.v4();
      let methodResponseWasSent = false;
      const deviceClient = DeviceClient.fromConnectionString(testDeviceConnectionString, DeviceMqtt);
      deviceClient.open(continueWith(() => {
        deviceClient.onDeviceMethod(testDeviceMethod.methodName, (request, response) => {
          response.send(200, continueWith(() => {
            methodResponseWasSent = true;
          }));
        });

        debug('scheduling a device method job with a sql query with the id: ' + testJobId);
        debug('Query: ' + 'deviceId = \'' + testDeviceId + '\'');
        jobClient.scheduleDeviceMethod(testJobId, 'deviceId = \'' + testDeviceId + '\'', testDeviceMethod, new Date(Date.now()), 120, continueWith(() => {
          waitForJobStatus(jobClient, testJobId, 'completed', continueWith(() => {
            const registry = Registry.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING);
            registry.getTwin(testDeviceId, continueWith(() => {
github Azure / azure-iot-sdk-node / ts-e2e / src / job_client.tests.ts View on Github external
it('schedules a twin update job and cancels it', (testCallback) => {
      const jobClient = JobClient.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING);
      const testJobId = uuid.v4();
      const fakePatch = {
        etag: '*',
        tags: {},
        properties: {
          desired: {},
          reported: {}
        }
      };
      jobClient.scheduleTwinUpdate(testJobId, 'deviceId = \'' + testDeviceId + '\'', fakePatch, new Date(Date.now() + 3600000), 120, continueWith((job) => {
        assert.strictEqual(job.jobId, testJobId);
        assert.strictEqual(job.status, 'queued');
        debug('cancelling job ' + testJobId);
        jobClient.cancelJob(testJobId, continueWith(() => {
          waitForJobStatus(jobClient, testJobId, 'cancelled', continueWith(() => {
            testCallback();
github Azure / azure-iot-sdk-node / ts-e2e / src / job_client.tests.ts View on Github external
it('schedules a device method job and cancels it', (testCallback) => {
      const jobClient = JobClient.fromConnectionString(process.env.IOTHUB_CONNECTION_STRING);
      const testJobId = uuid.v4();
      jobClient.scheduleDeviceMethod(testJobId, 'deviceId = \'' + testDeviceId + '\'', testDeviceMethod, new Date(Date.now() + 3600000), 120, continueWith((job) => {
        assert.strictEqual(job.jobId, testJobId);
        assert.strictEqual(job.status, 'queued');
        debug('cancelling job ' + testJobId);
        jobClient.cancelJob(testJobId, continueWith(() => {
          waitForJobStatus(jobClient, testJobId, 'cancelled', continueWith(testCallback));
        }));
      }));
    });
  });