Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/mararrdeveloper/pm2
Browse files Browse the repository at this point in the history
…into mararrdeveloper-development
  • Loading branch information
Unitech committed Feb 8, 2022
2 parents 5b896ee + 62afc6c commit 540caab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ 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 == 0 || app.cron_restart == '0') {
Common.printOut(cst.PREFIX_MSG + 'disabling cron restart');
Expand All @@ -339,7 +339,7 @@ Common.sink.determineCron = function(app) {
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 @@ -34,19 +34,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 @@ -59,7 +54,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

0 comments on commit 540caab

Please sign in to comment.