<commit_before>var fs = require('fs');
var async = require('async');
var cheerio = require('cheerio');
var request = require('request');
var twilio = require('twilio');

var configPath = process.argv[2] || 'config.json';
var twilioPath = process.argv[3] || 'twilio.json';
var queryArray = [];
var twilioClient, twilioSID, twilioToken, twilioNumber;

async.series([
  loadTwilioData,
  loadConfig,
  initQueries
]);

function loadTwilioData(callback){
  fs.readFile(twilioPath, function(err, data){
    if(err){
      console.error('failed to read Twilio config file');
      process.exit();
    }
    var parsedData = JSON.parse(data);
    twilioSID = parsedData.sid;
    twilioToken = parsedData.token;
    twilioNumber = parsedData.number;
    twilioClient = new twilio.RestClient(twilioSID, twilioToken);
    callback();
  });
}

function loadConfig(callback){
  var fileData;
  fs.readFile(configPath, function(err, data){
    if(err){
      console.error('failed to read config file');
      process.exit();
    }
    var parsedData = JSON.parse(data);
    var globalData = parsedData.global;
    setInterval(sendGlobalPing, globalData.pingInterval, globalData);
    var serverData = parsedData.servers;

    for(var rep=0;rep<serverData.length;rep++){
      var tempPage = {
        name: serverData[rep].name,
        url: serverData[rep].url,
        interval: serverData[rep].interval,
        errorInterval: serverData[rep].errorInterval,
        email: serverData[rep].email,
        sms: serverData[rep].sms
      };
      queryArray.push(tempPage);
    }
    callback();
  });
}

function sendGlobalPing(globalData){
  console.log('sending global ping');
  twilioClient.sms.messages.create({
    to: globalData.sms,
    from: twilioNumber,
    body: 'watchdog ping from: ' + globalData.instanceName
  }, function(err, reply){
    if(err){
      console.error('there was an error');
      console.log(err);<commit_msg>global ping is now also sent on startup<commit_after>var fs = require('fs');
var async = require('async');
var cheerio = require('cheerio');
var request = require('request');
var twilio = require('twilio');

var configPath = process.argv[2] || 'config.json';
var twilioPath = process.argv[3] || 'twilio.json';
var queryArray = [];
var twilioClient, twilioSID, twilioToken, twilioNumber;

async.series([
  loadTwilioData,
  loadConfig,
  initQueries
]);

function loadTwilioData(callback){
  fs.readFile(twilioPath, function(err, data){
    if(err){
      console.error('failed to read Twilio config file');
      process.exit();
    }
    var parsedData = JSON.parse(data);
    twilioSID = parsedData.sid;
    twilioToken = parsedData.token;
    twilioNumber = parsedData.number;
    twilioClient = new twilio.RestClient(twilioSID, twilioToken);
    callback();
  });
}

function loadConfig(callback){
  var fileData;
  fs.readFile(configPath, function(err, data){
    if(err){
      console.error('failed to read config file');
      process.exit();
    }
    var parsedData = JSON.parse(data);
    var globalData = parsedData.global;
    //send immediate global ping to let recipient know watchdog is running
    sendGlobalPing(globalData);
    setInterval(sendGlobalPing, globalData.pingInterval, globalData);
    var serverData = parsedData.servers;

    for(var rep=0;rep<serverData.length;rep++){
      var tempPage = {
        name: serverData[rep].name,
        url: serverData[rep].url,
        interval: serverData[rep].interval,
        errorInterval: serverData[rep].errorInterval,
        email: serverData[rep].email,
        sms: serverData[rep].sms
      };
      queryArray.push(tempPage);
    }
    callback();
  });
}

function sendGlobalPing(globalData){
  console.log('sending global ping');
  twilioClient.sms.messages.create({
    to: globalData.sms,
    from: twilioNumber,
    body: 'watchdog ping from: ' + globalData.instanceName
  }, function(err, reply){
    if(err){
      console.error('there was an error');
      console.log(err);
{'fraction_non_alphanumeric': 0.1319809666917105, 'fraction_numerical': 0.0015026296018031556, 'mean_word_length': 3.6988235294117646, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1800410', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1238, 'n_words': 274}