Skip to content

Commit

Permalink
Merge branch 'mararrdeveloper-development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Feb 9, 2022
2 parents f9bc048 + 2673a97 commit cbf5c0a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
7 changes: 3 additions & 4 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,8 @@ Common.retErr = function(e) {
Common.sink = {};

Common.sink.determineCron = function(app) {
var cronJob = require('cron').CronJob;
const cronParser = require('cron-parser')
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,9 +340,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() {
Common.printOut(cst.PREFIX_MSG + 'cron pattern for auto restart detected and valid');
});
cronParser.parseExpression(app.cron_restart);
} catch(ex) {
return new Error(`Cron pattern error: ${ex.message}`);
}
Expand Down
24 changes: 11 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,10 @@ module.exports = function(God) {
return;
console.log('[PM2] Deregistering a cron job on:', id);
var job = God.CronJobs.get(God.getCronID(id));
job.stop();

if (job)
job.cancel();

God.CronJobs.delete(God.getCronID(id));
};

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

0 comments on commit cbf5c0a

Please sign in to comment.