<commit_before>// A package for running jobs synchronized across multiple processes
SyncedCron = {
  _entries: [],
  options: {
    log: true,
    collectionName: 'cronHistory',
    utc: false //default to using localTime
  }
}

Later = Npm.require('later');

// Use UTC or localtime for evaluating schedules
if (SyncedCron.options.utc)
  Later.date.UTC();
else
  Later.date.localTime();

// collection holding the job history records
SyncedCron._collection = 
  new Meteor.Collection(SyncedCron.options.collectionName);
SyncedCron._collection._ensureIndex({intendedAt: 1, name: 1}, {unique: true});

var log = {
  info: function(message) {
    if (SyncedCron.options.log)
      console.log(message);
  }
}

// add a scheduled job
// SyncedCron.add({
//   name: String, //*required* unique name of the job
//   schedule: function(laterParser) {},//*required* when to run the job
//   job: function() {}, //*required* the code to run
// });
SyncedCron.add = function(entry) {
  check(entry.name, String);
  check(entry.schedule, Function);
  check(entry.job, Function);

  // check
  this._entries.push(entry);
}

// Start processing added jobs
SyncedCron.start = function() {
  var self = this;

  // Schedule each job with later.js
  this._entries.forEach(function(entry) {
    var schedule = entry.schedule(Later.parse);
    self._timer = self._laterSetInterval(self._entryWrapper(entry), schedule);

    log.info('SyncedCron: scheduled "' + entry.name + '" next run @' 
      + Later.schedule(schedule).next(1));
  });
}

// Return the next scheduled date of the first matching entry or undefined
SyncedCron.nextScheduledAtDate = function (jobName) {
  var entry = _.find(this._entries, function(entry) {
    return entry.name === jobName;
  });
  
  if (entry)
    return Later.schedule(entry.schedule(Later.parse)).next(1);
}

// Stop processing jobs<commit_msg>Correctly sets _timer on entry<commit_after>// A package for running jobs synchronized across multiple processes
SyncedCron = {
  _entries: [],
  options: {
    log: true,
    collectionName: 'cronHistory',
    utc: false //default to using localTime
  }
}

Later = Npm.require('later');

// Use UTC or localtime for evaluating schedules
if (SyncedCron.options.utc)
  Later.date.UTC();
else
  Later.date.localTime();

// collection holding the job history records
SyncedCron._collection = 
  new Meteor.Collection(SyncedCron.options.collectionName);
SyncedCron._collection._ensureIndex({intendedAt: 1, name: 1}, {unique: true});

var log = {
  info: function(message) {
    if (SyncedCron.options.log)
      console.log(message);
  }
}

// add a scheduled job
// SyncedCron.add({
//   name: String, //*required* unique name of the job
//   schedule: function(laterParser) {},//*required* when to run the job
//   job: function() {}, //*required* the code to run
// });
SyncedCron.add = function(entry) {
  check(entry.name, String);
  check(entry.schedule, Function);
  check(entry.job, Function);

  // check
  this._entries.push(entry);
}

// Start processing added jobs
SyncedCron.start = function() {
  var self = this;

  // Schedule each job with later.js
  this._entries.forEach(function(entry) {
    var schedule = entry.schedule(Later.parse);
    entry._timer = self._laterSetInterval(self._entryWrapper(entry), schedule);

    log.info('SyncedCron: scheduled "' + entry.name + '" next run @' 
      + Later.schedule(schedule).next(1));
  });
}

// Return the next scheduled date of the first matching entry or undefined
SyncedCron.nextScheduledAtDate = function (jobName) {
  var entry = _.find(this._entries, function(entry) {
    return entry.name === jobName;
  });
  
  if (entry)
    return Later.schedule(entry.schedule(Later.parse)).next(1);
}

// Stop processing jobs
{'fraction_non_alphanumeric': 0.13752665245202558, 'fraction_numerical': 0.0021321961620469083, 'mean_word_length': 3.7326607818411097, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5072136', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1158, 'n_words': 309}