Skip to content

Commit

Permalink
Ability to view stdout added
Browse files Browse the repository at this point in the history
  • Loading branch information
alseambusher committed Nov 27, 2019
1 parent 9d5238b commit ee3aad8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
20 changes: 15 additions & 5 deletions app.js
Expand Up @@ -184,13 +184,23 @@ app.get(routes.import_crontab, function(req, res) {
res.end();
});

// get the log file a given job. id passed as query param
app.get(routes.logger, function(req, res) {
_file = crontab.log_folder +"/"+req.query.id+".log";
if (fs.existsSync(_file))
res.sendFile(_file);
function sendLog(path, req, res) {
if (fs.existsSync(path))
res.sendFile(path);
else
res.end("No errors logged yet");
}

// get the log file a given job. id passed as query param
app.get(routes.logger, function(req, res) {
let _file = crontab.log_folder + "/" + req.query.id + ".log";
sendLog(_file, req, res);
});

// get the log file a given job. id passed as query param
app.get(routes.stdout, function(req, res) {
let _file = crontab.log_folder + "/" + req.query.id + ".stdout.log";
sendLog(_file, req, res);
});

// error handler
Expand Down
6 changes: 6 additions & 0 deletions crontab.js
Expand Up @@ -95,6 +95,7 @@ exports.set_crontab = function(env_vars, callback){
let stderr = path.join(cronPath, tab._id + ".stderr");
let stdout = path.join(cronPath, tab._id + ".stdout");
let log_file = path.join(exports.log_folder, tab._id + ".log");
let log_file_stdout = path.join(exports.log_folder, tab._id + ".stdout.log");

if(tab.command[tab.command.length-1] != ";") // add semicolon
tab.command +=";";
Expand All @@ -106,6 +107,11 @@ exports.set_crontab = function(env_vars, callback){
"; then date >> \"" + log_file + "\"" +
"; cat " + stderr + " >> \"" + log_file + "\"" +
"; fi";

crontab_string += "; if test -f " + stdout +
"; then date >> \"" + log_file_stdout + "\"" +
"; cat " + stdout + " >> \"" + log_file_stdout + "\"" +
"; fi";
}

if (tab.hook) {
Expand Down
1 change: 1 addition & 0 deletions routes.js
Expand Up @@ -14,4 +14,5 @@ exports.routes = {
"import": "/import", // this is import from database
"import_crontab": "/import_crontab", // this is from existing crontab
"logger": "/logger",
"stdout": "/stdout",
};
3 changes: 2 additions & 1 deletion views/index.ejs
Expand Up @@ -82,7 +82,8 @@
<!-- controls based on crontab state -->
<% if (!crontab.stopped) { %>
<% if (crontab.logging && crontab.logging != "false") {%>
<a class="btn btn-primary" data-toggle="tooltip" data-placement="left" title="See Log" href="<%= JSON.parse(routes).logger + '?id=' + crontab._id %>" target="_blank"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a>
<a class="btn btn-primary btn-danger" data-toggle="tooltip" data-placement="left" title="stderr" href="<%= JSON.parse(routes).logger + '?id=' + crontab._id %>" target="_blank"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a>
<a class="btn btn-primary" data-toggle="tooltip" data-placement="left" title="stdout" href="<%= JSON.parse(routes).stdout + '?id=' + crontab._id %>" target="_blank"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a>
<% } %>
<a class="btn btn-info" onclick="runJob('<%= crontab._id %>')"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Run</a>
<a class="btn btn-primary" onclick="editJob('<%= crontab._id %>')"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Edit</a>
Expand Down

0 comments on commit ee3aad8

Please sign in to comment.