Skip to content

Commit

Permalink
Handle case where there is invalid cron time expression
Browse files Browse the repository at this point in the history
  • Loading branch information
alseambusher committed Jun 8, 2020
1 parent 42e677d commit 970e461
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ app.use(function(err, req, res, next) {
data.stack = err.stack;
}

if (parseInt(data.statusCode) >= 500) {
if (statusCode >= 500) {
console.error(err);
}

Expand Down
18 changes: 15 additions & 3 deletions crontab.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ exports.crontabs = function(callback){
if(docs[i].schedule == "@reboot")
docs[i].next = "Next Reboot";
else
docs[i].next = cron_parser.parseExpression(docs[i].schedule).next().toString();
try {
docs[i].next = cron_parser.parseExpression(docs[i].schedule).next().toString();
} catch(err) {
console.error(err);
docs[i].next = "invalid";
}
}
callback(docs);
});
Expand Down Expand Up @@ -129,11 +134,18 @@ exports.set_crontab = function(env_vars, callback){
});

fs.writeFile(exports.env_file, env_vars, function(err) {
if (err) callback(err);
if (err) {
console.error(err);
callback(err);
}
// In docker we're running as the root user, so we need to write the file as root and not crontab
var fileName = process.env.CRON_IN_DOCKER !== undefined ? "root" : "crontab";
fs.writeFile(path.join(cronPath, fileName), crontab_string, function(err) {
if (err) return callback(err);
if (err) {
console.error(err);
return callback(err);
}

exec("crontab " + path.join(cronPath, fileName), function(err) {
if (err) {
console.error(err);
Expand Down

0 comments on commit 970e461

Please sign in to comment.