diff --git a/lib/Common.js b/lib/Common.js index 8e0eeda0e..2d9184539 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -329,15 +329,14 @@ 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') { Common.printOut(cst.PREFIX_MSG + 'disabling cron restart'); return } if (app.cron_restart) { + const cronParser = require('cron-parser') + try { Common.printOut(cst.PREFIX_MSG + 'cron restart at ' + app.cron_restart); cronParser.parseExpression(app.cron_restart); diff --git a/lib/Worker.js b/lib/Worker.js index 924489d48..265fc6892 100644 --- a/lib/Worker.js +++ b/lib/Worker.js @@ -3,14 +3,15 @@ * Use of this source code is governed by a license that * can be found in the LICENSE file. */ -var vizion = require('vizion'); -var cst = require('../constants.js'); -var eachLimit = require('async/eachLimit'); -var debug = require('debug')('pm2:worker'); -var domain = require('domain'); -const scheduleJob = require('node-schedule').scheduleJob; +const vizion = require('vizion'); +const eachLimit = require('async/eachLimit'); +const debug = require('debug')('pm2:worker'); +const domain = require('domain'); +const Cron = require('croner'); +const pkg = require('../package.json'); + +var cst = require('../constants.js'); var vCheck = require('./VersionCheck.js') -var pkg = require('../package.json') module.exports = function(God) { var timer = null; @@ -34,7 +35,7 @@ module.exports = function(God) { var pm_id = pm2_env.pm_id console.log('[PM2][WORKER] Registering a cron job on:', pm_id); - var job = scheduleJob(pm2_env.cron_restart, function() { + var job = Cron(pm2_env.cron_restart, function() { God.restartProcessId({id: pm_id}, function(err, data) { if (err) console.error(err.stack || err); @@ -56,7 +57,7 @@ module.exports = function(God) { var job = God.CronJobs.get(God.getCronID(id)); if (job) - job.cancel(); + job.stop(); God.CronJobs.delete(God.getCronID(id)); }; diff --git a/package.json b/package.json index c05e95f85..bc8341920 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,7 @@ "chokidar": "^3.5.1", "cli-tableau": "^2.0.0", "commander": "2.15.1", - "node-schedule": "^2.0.0", + "croner": "~4.1.92", "cron-parser": "~3.5.0", "dayjs": "~1.8.25", "debug": "^4.3.1",