mirror of
https://github.com/strapi/strapi.git
synced 2025-07-12 11:31:38 +00:00
43 lines
642 B
JavaScript
43 lines
642 B
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
// Public node modules.
|
|
const _ = require('lodash');
|
|
const cron = require('node-schedule');
|
|
|
|
/**
|
|
* CRON hook
|
|
*/
|
|
|
|
module.exports = function (strapi) {
|
|
const hook = {
|
|
|
|
/**
|
|
* Default options
|
|
*/
|
|
|
|
defaults: {
|
|
cron: {}
|
|
},
|
|
|
|
/**
|
|
* Initialize the hook
|
|
*/
|
|
|
|
initialize: function (cb) {
|
|
if (_.isPlainObject(strapi.config.cron) && !_.isEmpty(strapi.config.cron)) {
|
|
_.forEach(_.keys(strapi.config.cron), function (task) {
|
|
cron.scheduleJob(task, strapi.config.cron[task]);
|
|
});
|
|
}
|
|
|
|
cb();
|
|
}
|
|
};
|
|
|
|
return hook;
|
|
};
|