My child.stderr.on() and child.stderr.on() both use a callback which returns a duration value(its just a number representing an execution time in ms).
I'd like to use this in my child.on(). I thought I could declare a variable outside the functions, assign the duration to it in my functions then use it in my child.on(). I've included my fnctions below. The child.stdout.on is the same as child.stdout.on. Can this be done?
child.stdout.on('data', function(data, callback) {
getEventLog.getId(id, uuid, function(err, id, code, callback){
//if(err) return console.log(err)
console.log("ID: " + id);
getEventLog.getDuration(id, uuid, function(err, duration, callback){
jobRun.duration = duration;
})
});
});
child.on('close', function(code, duration) {
var logMessage =
"Completed jobRunId " + jobRun.id + " (" + jobRun.jobsId + ") " + jobRun.jobType +
" run " + jobRun.runNumber + " in " + jobRun.duration + " with exit code " + code;
jobLogger.info(logMessage + "<br />");
callback(jobRun.id);
});
When I run the above I get this:
Completed jobRunId 818 (601) teragen run 6 in 9813ms with exit code undefined