text: // 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;
  if (!connectionString) {
    console.log('Please set the IOTHUB_CONNECTION_STRING environment variable.');
    process.exit(-1);
  }
  
  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);
      }
    }
  };
  
  query.next(onResults);