Skip to content

Commit 2673a97

Browse files
committed
fix cron check
1 parent 540caab commit 2673a97

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/Common.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ Common.retErr = function(e) {
329329
Common.sink = {};
330330

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

334335
if (app.cron_restart == 0 || app.cron_restart == '0') {
@@ -339,9 +340,7 @@ Common.sink.determineCron = function(app) {
339340
if (app.cron_restart) {
340341
try {
341342
Common.printOut(cst.PREFIX_MSG + 'cron restart at ' + app.cron_restart);
342-
scheduleJob(app.cron_restart, function() {
343-
Common.printOut(cst.PREFIX_MSG + 'cron pattern for auto restart detected and valid');
344-
});
343+
cronParser.parseExpression(app.cron_restart);
345344
} catch(ex) {
346345
return new Error(`Cron pattern error: ${ex.message}`);
347346
}

lib/Worker.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ module.exports = function(God) {
5454
return;
5555
console.log('[PM2] Deregistering a cron job on:', id);
5656
var job = God.CronJobs.get(God.getCronID(id));
57-
job.cancel();
57+
58+
if (job)
59+
job.cancel();
60+
5861
God.CronJobs.delete(God.getCronID(id));
5962
};
6063

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
"cli-tableau": "^2.0.0",
178178
"commander": "2.15.1",
179179
"node-schedule": "^2.0.0",
180+
"cron-parser": "~3.5.0",
180181
"dayjs": "~1.8.25",
181182
"debug": "^4.3.1",
182183
"enquirer": "2.3.6",

0 commit comments

Comments
 (0)