Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced cron with node-schedule #5184

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ Common.retErr = function(e) {
Common.sink = {};

Common.sink.determineCron = function(app) {
var cronJob = require('cron').CronJob;
const scheduleJob = require('node-schedule').scheduleJob;

if (app.cron_restart) {
try {
Common.printOut(cst.PREFIX_MSG + 'cron restart at ' + app.cron_restart);
new cronJob(app.cron_restart, function() {
scheduleJob(app.cron_restart, function() {
Common.printOut(cst.PREFIX_MSG + 'cron pattern for auto restart detected and valid');
});
} catch(ex) {
Expand Down
21 changes: 8 additions & 13 deletions lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var cst = require('../constants.js');
var eachLimit = require('async/eachLimit');
var debug = require('debug')('pm2:worker');
var domain = require('domain');
var cronJob = require('cron').CronJob
const scheduleJob = require('node-schedule').scheduleJob;
var vCheck = require('./VersionCheck.js')
var pkg = require('../package.json')

Expand All @@ -33,19 +33,14 @@ module.exports = function(God) {
var pm_id = pm2_env.pm_id
console.log('[PM2][WORKER] Registering a cron job on:', pm_id);

var job = new cronJob({
cronTime: pm2_env.cron_restart,
onTick: function() {
God.restartProcessId({id: pm_id}, function(err, data) {
if (err)
console.error(err.stack || err);
return;
});
},
start: false
var job = scheduleJob(pm2_env.cron_restart, function() {
God.restartProcessId({id: pm_id}, function(err, data) {
if (err)
console.error(err.stack || err);
return;
});
});

job.start();
God.CronJobs.set(God.getCronID(pm_id), job);
}

Expand All @@ -58,7 +53,7 @@ module.exports = function(God) {
return;
console.log('[PM2] Deregistering a cron job on:', id);
var job = God.CronJobs.get(God.getCronID(id));
job.stop();
job.cancel();
God.CronJobs.delete(God.getCronID(id));
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"chokidar": "^3.5.1",
"cli-tableau": "^2.0.0",
"commander": "2.15.1",
"cron": "1.8.2",
"node-schedule": "^2.0.0",
"dayjs": "~1.8.25",
"debug": "^4.3.1",
"enquirer": "2.3.6",
Expand Down