|
|
|
@ -10,7 +10,7 @@ var jobs = {};
|
|
|
|
|
module.exports = function (User) {
|
|
|
|
|
User.startJobs = function (callback) {
|
|
|
|
|
winston.verbose('[user/jobs] (Re-)starting user jobs...');
|
|
|
|
|
var terminated = 0;
|
|
|
|
|
|
|
|
|
|
var started = 0;
|
|
|
|
|
var digestHour = parseInt(meta.config.digestHour, 10);
|
|
|
|
|
|
|
|
|
@ -21,37 +21,12 @@ module.exports = function (User) {
|
|
|
|
|
digestHour = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Terminate any active cron jobs
|
|
|
|
|
for (var jobId in jobs) {
|
|
|
|
|
if (jobs.hasOwnProperty(jobId)) {
|
|
|
|
|
winston.verbose('[user/jobs] Terminating job (' + jobId + ')');
|
|
|
|
|
jobs[jobId].stop();
|
|
|
|
|
delete jobs[jobId];
|
|
|
|
|
terminated += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
winston.verbose('[user/jobs] ' + terminated + ' jobs terminated');
|
|
|
|
|
User.stopJobs();
|
|
|
|
|
|
|
|
|
|
jobs['digest.daily'] = new cronJob('0 ' + digestHour + ' * * *', function () {
|
|
|
|
|
winston.verbose('[user/jobs] Digest job (daily) started.');
|
|
|
|
|
User.digest.execute('day');
|
|
|
|
|
}, null, true);
|
|
|
|
|
winston.verbose('[user/jobs] Starting job (digest.daily)');
|
|
|
|
|
started += 1;
|
|
|
|
|
|
|
|
|
|
jobs['digest.weekly'] = new cronJob('0 ' + digestHour + ' * * 0', function () {
|
|
|
|
|
winston.verbose('[user/jobs] Digest job (weekly) started.');
|
|
|
|
|
User.digest.execute('week');
|
|
|
|
|
}, null, true);
|
|
|
|
|
winston.verbose('[user/jobs] Starting job (digest.weekly)');
|
|
|
|
|
started += 1;
|
|
|
|
|
|
|
|
|
|
jobs['digest.monthly'] = new cronJob('0 ' + digestHour + ' 1 * *', function () {
|
|
|
|
|
winston.verbose('[user/jobs] Digest job (monthly) started.');
|
|
|
|
|
User.digest.execute('month');
|
|
|
|
|
}, null, true);
|
|
|
|
|
winston.verbose('[user/jobs] Starting job (digest.monthly)');
|
|
|
|
|
started += 1;
|
|
|
|
|
startDigestJob('digest.daily', '0 ' + digestHour + ' * * *', 'day');
|
|
|
|
|
startDigestJob('digest.weekly', '0 ' + digestHour + ' * * 0', 'week');
|
|
|
|
|
startDigestJob('digest.monthly', '0 ' + digestHour + ' 1 * *', 'month');
|
|
|
|
|
started += 3;
|
|
|
|
|
|
|
|
|
|
jobs['reset.clean'] = new cronJob('0 0 * * *', User.reset.clean, null, true);
|
|
|
|
|
winston.verbose('[user/jobs] Starting job (reset.clean)');
|
|
|
|
@ -63,5 +38,29 @@ module.exports = function (User) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function startDigestJob(name, cronString, term) {
|
|
|
|
|
jobs[name] = new cronJob(cronString, function () {
|
|
|
|
|
winston.verbose('[user/jobs] Digest job (' + name + ') started.');
|
|
|
|
|
User.digest.execute(term);
|
|
|
|
|
}, null, true);
|
|
|
|
|
winston.verbose('[user/jobs] Starting job (' + name + ')');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User.stopJobs = function () {
|
|
|
|
|
var terminated = 0;
|
|
|
|
|
// Terminate any active cron jobs
|
|
|
|
|
for (var jobId in jobs) {
|
|
|
|
|
if (jobs.hasOwnProperty(jobId)) {
|
|
|
|
|
winston.verbose('[user/jobs] Terminating job (' + jobId + ')');
|
|
|
|
|
jobs[jobId].stop();
|
|
|
|
|
delete jobs[jobId];
|
|
|
|
|
terminated += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (terminated > 0) {
|
|
|
|
|
winston.verbose('[user/jobs] ' + terminated + ' jobs terminated');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|