diff --git a/lib/API/schema.json b/lib/API/schema.json index 0f758a086..9713c1d24 100644 --- a/lib/API/schema.json +++ b/lib/API/schema.json @@ -168,7 +168,10 @@ "docDescription": "Time in ms before forcing a reload if app is still not listening/has still note sent ready" }, "cron_restart": { - "type": "string", + "type": [ + "string", + "number" + ], "alias": "cron", "docDescription": "A cron pattern to restart your app" }, diff --git a/lib/Common.js b/lib/Common.js index ceef73fee..9d16ce278 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -331,6 +331,11 @@ Common.sink = {}; Common.sink.determineCron = function(app) { var cronJob = require('cron').CronJob; + if (app.cron_restart == 0 || app.cron_restart == '0') { + Common.printOut(cst.PREFIX_MSG + 'disabling cron restart'); + return + } + if (app.cron_restart) { try { Common.printOut(cst.PREFIX_MSG + 'cron restart at ' + app.cron_restart); diff --git a/lib/God/ActionMethods.js b/lib/God/ActionMethods.js index 5e7d2e31c..51e4c3db2 100644 --- a/lib/God/ActionMethods.js +++ b/lib/God/ActionMethods.js @@ -396,6 +396,7 @@ module.exports = function(God) { var proc = God.clusters_db[id]; God.resetState(proc.pm2_env); + God.deleteCron(id); /** * Merge new application configuration on restart diff --git a/lib/Worker.js b/lib/Worker.js index 0dbf88787..2cab0a749 100644 --- a/lib/Worker.js +++ b/lib/Worker.js @@ -27,6 +27,7 @@ module.exports = function(God) { if (!pm2_env || pm2_env.pm_id === undefined || !pm2_env.cron_restart || + pm2_env.cron_restart == '0' || God.CronJobs.has(God.getCronID(pm2_env.pm_id))) return; diff --git a/test/e2e/misc/cron-system.sh b/test/e2e/misc/cron-system.sh index 14f3415bf..b6cb6043a 100644 --- a/test/e2e/misc/cron-system.sh +++ b/test/e2e/misc/cron-system.sh @@ -66,3 +66,20 @@ sleep 4 should 'should app been restarted' 'restart_time: 0' 0 $pm2 delete all + +# +# Cron every sec +# +$pm2 start cron.js -c "* * * * * *" +sleep 4 +should 'should app been restarted' 'restart_time: 0' 0 + +# +# Delete cron +# +$pm2 restart cron --cron-restart 0 +$pm2 reset all +sleep 2 +should 'app stop be restarted' 'restart_time: 0' 1 + +$pm2 delete all