Log into file when executed by "Run"
parent
7bf1135a81
commit
8692ae8e20
12
crontab.js
12
crontab.js
|
@ -13,8 +13,8 @@ if(process.env.CRON_PATH !== undefined) {
|
||||||
db.loadDatabase(function (err) {
|
db.loadDatabase(function (err) {
|
||||||
if (err) throw err; // no hope, just terminate
|
if (err) throw err; // no hope, just terminate
|
||||||
});
|
});
|
||||||
|
var childProcess = require('child_process');
|
||||||
var exec = require('child_process').exec;
|
var exec = childProcess.exec;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var cron_parser = require("cron-parser");
|
var cron_parser = require("cron-parser");
|
||||||
|
|
||||||
|
@ -76,10 +76,10 @@ exports.get_crontab = function(_id, callback) {
|
||||||
|
|
||||||
exports.runjob = function(_id, callback) {
|
exports.runjob = function(_id, callback) {
|
||||||
db.find({_id: _id}).exec(function(err, docs){
|
db.find({_id: _id}).exec(function(err, docs){
|
||||||
var res = docs[0];
|
var res = docs[0];
|
||||||
exec(res.command, function(error, stdout, stderr){
|
var output = fs.openSync(path.join(exports.log_folder, _id + ".log"), 'w');
|
||||||
console.log(stdout);
|
var output2 = fs.openSync(path.join(exports.log_folder, _id + ".log"), 'a');
|
||||||
});
|
childProcess.spawn('sh', ['-c', res.command], {stdio: ['ignore', output, output2]});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue