Skip to content

Commit

Permalink
fix cron check
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Feb 8, 2022
1 parent 540caab commit 2673a97
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ Common.retErr = function(e) {
Common.sink = {};

Common.sink.determineCron = function(app) {
const cronParser = require('cron-parser')
const scheduleJob = require('node-schedule').scheduleJob;

if (app.cron_restart == 0 || app.cron_restart == '0') {
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);
scheduleJob(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
5 changes: 4 additions & 1 deletion lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,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.cancel();

if (job)
job.cancel();

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

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
"cli-tableau": "^2.0.0",
"commander": "2.15.1",
"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 2673a97

Please sign in to comment.