var createJob = require('./createJob');

module.exports = function (sails) {
  return {
    jobs: {},

    defaults: {cron: {}},

    initialize: function (cb) {
      var config = sails.config.cron;
      var tasks = Object.keys(config);
      tasks.forEach(function (time) {
        this.jobs[time] = createJob({
          cronTime: time,
          onTick: config[time] instanceof Function ? config[time] : config[time].onTick,
          onComplete: config[time].onComplete,
          start: typeof config[time].start === 'boolean' ? config[time].start : true,
          timezone: config[time].timezone,
          context: config[time].context
        });
      }.bind(this));

      cb();
    }
  };
};

var createJob = require('./createJob');

module.exports = function (sails) {
  return {
    jobs: {},

    defaults: {cron: {}},

    initialize: function (cb) {
      var config = sails.config.cron;
      var tasks = Object.keys(config);
      tasks.forEach(function (name) {
        this.jobs[name] = createJob({
          cronTime: config[name].schedule,
          onTick: config[name].onTick,
          onComplete: config[name].onComplete,
          start: typeof config[name].start === 'boolean' ? config[name].start : true,
          timezone: config[name].timezone,
          context: config[name].context
        });
      }.bind(this));

      cb();
    }
  };
};

Replace schedule as a key with named job
Replace schedule as a key with named job
