diff --git a/app.js b/app.js index be68cd4..c1b2202 100755 --- a/app.js +++ b/app.js @@ -87,6 +87,12 @@ app.post(routes.remove, function(req, res) { res.end(); }); +// run a job +app.post(routes.run, function(req, res) { + crontab.runjob(req.body._id); + res.end(); +}); + // set crontab. Needs env_vars to be passed app.get(routes.crontab, function(req, res, next) { crontab.set_crontab(req.query.env_vars, function(err) { diff --git a/crontab.js b/crontab.js index b32887a..c195d2b 100644 --- a/crontab.js +++ b/crontab.js @@ -74,6 +74,15 @@ exports.get_crontab = function(_id, callback) { }); }; +exports.runjob = function(_id, callback) { + db.find({_id: _id}).exec(function(err, docs){ + var res = docs[0]; + exec(res.command, function(error, stdout, stderr){ + console.log(stdout); + }); + }); +}; + // Set actual crontab file from the db exports.set_crontab = function(env_vars, callback){ exports.crontabs( function(tabs){ diff --git a/public/js/script.js b/public/js/script.js index 5d08916..9421f03 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -55,6 +55,15 @@ function startJob(_id){ }); } +function runJob(_id){ + messageBox("
Do you want to run this Job?
", "Confirm run job", null, null, function(){ + $.post(routes.run, {_id: _id}, function(){ + location.reload(); + }); + + }); +} + function setCrontab(){ messageBox("Do you want to set the crontab file?
", "Confirm crontab setup", null, null, function(){ $.get(routes.crontab, { "env_vars": $("#env_vars").val() }, function(){ diff --git a/routes.js b/routes.js index 191d26c..210f79e 100644 --- a/routes.js +++ b/routes.js @@ -1,6 +1,7 @@ exports.routes = { "root" : "/", "save" : "/save", + "run" : "/runjob", "crontab" : "/crontab", "stop" : "/stop", "start" : "/start", diff --git a/views/index.ejs b/views/index.ejs index a972b39..9c76400 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -84,6 +84,7 @@ <% if (crontab.logging && crontab.logging != "false") {%> <% } %> + Run Edit Stop <% } else { %>