add cRonstrue, parses a cron expression and outputs a human readable description of the cron schedule

pull/170/head
Hasan Basri 3 years ago
parent 4941a7e5b8
commit f02c748c52

@ -11,7 +11,6 @@ exports.crontab_db_file = path.join(exports.db_folder, 'crontab.db');
var db = new Datastore({ filename: exports.crontab_db_file});
var cronPath = "/tmp";
if(process.env.CRON_PATH !== undefined) {
console.log(`Path to crond files set using env variables ${process.env.CRON_PATH}`);
cronPath = process.env.CRON_PATH;
@ -24,6 +23,8 @@ db.loadDatabase(function (err) {
var exec = require('child_process').exec;
var fs = require('fs');
var cron_parser = require("cron-parser");
var cronstrue = require('cronstrue/i18n');
var humanCronLocate = process.env.HUMANCRON ?? "en"
crontab = function(name, command, schedule, stopped, logging, mailing){
@ -71,6 +72,7 @@ exports.crontabs = function(callback){
docs[i].next = "Next Reboot";
else
try {
docs[i].human = cronstrue.toString(docs[i].schedule, { locale: humanCronLocate });
docs[i].next = cron_parser.parseExpression(docs[i].schedule).next().toString();
} catch(err) {
console.error(err);

@ -11,6 +11,7 @@
"body-parser": "latest",
"connect-busboy": "latest",
"cron-parser": "latest",
"cronstrue": "^1.115.0",
"ejs": "latest",
"express": "latest",
"express-basic-auth": "^1.2.0",

@ -82,7 +82,8 @@
<% } %>
</td>
<td><%= crontab.command %></td>
<td><span style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" title="<%= crontab.next %>"><%= crontab.schedule %></span></td>
<td><span style="cursor:pointer" data-toggle="tooltip" data-placement="bottom" title="<%= crontab
.next %>"><%= crontab.schedule %><br><%= crontab.human %></span></td>
<td style="width:20%" title="<%= crontab.timestamp %>"><%= moment(new Date(crontab.timestamp)).fromNow() %></td>
<td>

Loading…
Cancel
Save