<commit_before>// Essentially cron for scheduling tasks in Node.

const assert  = require('assert');
const ms      = require('ms');
const Promise = require('bluebird');
const runJob  = require('./run_job');


// Job schedule consists of three properties:
// name  - Schedule name (for reporting)
// job   - Job to run
// start - Start running after this time
// every - Run every so many seconds
// end   - Do not run after this time
//
// A schedule can have a start time, but no other properties, in which case the
// job will run exactly once, if the start time is in the future.
//
// A schedule can have recurrence, in which case the job will run every so many
// seconds, with optional start and end time.
class Schedule {

  constructor(scheduler, name, time, job) {
    this._scheduler = scheduler;
    this._notify    = scheduler._notify;

    assert(name, 'Schedule missing name');
    this.name = name;
    assert(typeof(job) == 'function', 'Schedule missing job function');
    this.job  = job;

    if (time instanceof Date) {
      this.startTime = time.getTime();
    } else if (typeof(time) == 'string') {
      this.every = ms(time);
    } else if (typeof(time) == 'number') {
      this.every = parseInt(time, 0);
    } else if (typeof(time) == 'object') {
      const { start, every, end } = time;
      this.startTime = start ? +start : undefined;
      this.endTime   = end   ? +end   : undefined;
      this.every     = (typeof(every) == 'string' ? ms(every) : parseInt(every, 0));
    } else
      throw new Error('Schedule time must be Date (instance), Number (interval) or object with start/every/end properties');

    assert(this.startTime || this.every, 'Schedule requires either start time or interval (0 not acceptable)');<commit_msg>Linted src/schedule.js<commit_after>// Essentially cron for scheduling tasks in Node.

const assert  = require('assert');
const ms      = require('ms');
const Promise = require('bluebird');
const runJob  = require('./run_job');


// Job schedule consists of three properties:
// name  - Schedule name (for reporting)
// job   - Job to run
// start - Start running after this time
// every - Run every so many seconds
// end   - Do not run after this time
//
// A schedule can have a start time, but no other properties, in which case the
// job will run exactly once, if the start time is in the future.
//
// A schedule can have recurrence, in which case the job will run every so many
// seconds, with optional start and end time.
class Schedule {

  constructor(scheduler, name, time, job) {
    this._scheduler = scheduler;
    this._notify    = scheduler._notify;

    assert(name, 'Schedule missing name');
    this.name = name;
    assert(typeof job === 'function', 'Schedule missing job function');
    this.job  = job;

    if (time instanceof Date)
      this.startTime = time.getTime();
    else if (typeof time === 'string')
      this.every = ms(time);
    else if (typeof time === 'number')
      this.every = parseInt(time, 0);
    else if (typeof time === 'object') {
      const { start, every, end } = time;
      this.startTime = start ? +start : undefined;
      this.endTime   = end   ? +end   : undefined;
      this.every     = (typeof every === 'string' ? ms(every) : parseInt(every, 0));
    } else
      throw new Error('Schedule time must be Date (instance), Number (interval) or object with start/every/end properties');

    assert(this.startTime || this.every, 'Schedule requires either start time or interval (0 not acceptable)');
{'fraction_non_alphanumeric': 0.12226950354609929, 'fraction_numerical': 0.001702127659574468, 'mean_word_length': 3.029714285714286, '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': '5853817', 'n_tokens_mistral': 991, 'n_tokens_neox': 972, 'n_words': 401}