Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app cron_timezone option to change the timezone used in cron_restart #5877

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/API/UX/pm2-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ module.exports = function(proc) {
}

if ('cron_restart' in pm2_env){
if ('cron_timezone' in pm2_env){
table.splice(5, 0, {'cron timezone': pm2_env.cron_timezone})
}
table.splice(5, 0, {'cron restart': pm2_env.cron_restart})
}

Expand Down
4 changes: 4 additions & 0 deletions lib/API/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@
"alias": "cron",
"docDescription": "A cron pattern to restart your app"
},
"cron_timezone": {
"type": "string",
"docDescription": "Timezone in Europe/Stockholm format"
},
"merge_logs": {
"type": "boolean",
"alias" : "combine_logs",
Expand Down
11 changes: 9 additions & 2 deletions lib/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,15 @@ Common.sink.determineCron = function(app) {
const Croner = require('croner');

try {
Common.printOut(cst.PREFIX_MSG + 'cron restart at ' + app.cron_restart);
Croner(app.cron_restart);
Common.printOut(cst.PREFIX_MSG + 'cron restart at ' + app.cron_restart + " in " +
(app.cron_timezone ? app.cron_timezone : "default timezone"));

let croner_options;
if (app.cron_timezone) {
croner_options = { timezone: app.cron_timezone };
}

Croner(app.cron_restart, croner_options);
} catch(ex) {
return new Error(`Cron pattern error: ${ex.message}`);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ module.exports = function(God) {
var pm_id = pm2_env.pm_id
console.log('[PM2][WORKER] Registering a cron job on:', pm_id);

var job = Cron(pm2_env.cron_restart, function() {
let croner_options;
if (pm2_env.cron_timezone) {
croner_options = { timezone: pm2_env.cron_timezone };
}

var job = Cron(pm2_env.cron_restart, croner_options, function() {
God.restartProcessId({id: pm_id}, function(err, data) {
if (err)
console.error(err.stack || err);
Expand Down