Skip to content

Commit

Permalink
job logging update
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeTWC1984 committed Oct 26, 2023
1 parent 6a63851 commit c45c55b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/api/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ module.exports = Class.create({
}); // loaded session
},

safeJobLog(job) { // print less verbose, more readable job data on logging
if(!job) return ''
return Object.keys(job).filter(e => ! ["table", "secret", "env"].includes(e)).map(e => e + ': ' + ("params|workflow|perf".indexOf(e) > -1 ? JSON.stringify(job[e]) : job[e]) ).join(" | ")
},

api_get_event: function (args, callback) {
// get single event for editing
var self = this;
Expand Down Expand Up @@ -477,7 +482,7 @@ module.exports = Class.create({
job.username = user.username;
}

self.logDebug(6, "Running event manually: " + job.title, job);
self.logDebug(6, "Running event manually: " + job.title, self.safeJobLog(job));

self.launchOrQueueJob(job, function (err, jobs_launched) {
if (err) {
Expand Down
17 changes: 11 additions & 6 deletions lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ module.exports = Class.create({
});
},

safeJobLog(job) { // print less verbose, more readable job data on logging
if(!job) return ''
return Object.keys(job).filter(e => ! ["table", "secret", "env"].includes(e)).map(e => e + ': ' + ("params|workflow|perf".indexOf(e) > -1 ? JSON.stringify(job[e]) : job[e]) ).join(" | ")
},

launchJob: function (event, callback) {
// locate suitable server and launch job
var self = this;
Expand Down Expand Up @@ -496,7 +501,7 @@ module.exports = Class.create({
job.id + (job.detached ? '-detached' : '') + '.log'
));

this.logDebug(6, "Launching local job", job);
this.logDebug(6, "Launching local job", this.safeJobLog(job));

// if we are the manager server or job is detached,
// save copy of job file to disk next to log (for crash recovery)
Expand Down Expand Up @@ -1016,7 +1021,7 @@ module.exports = Class.create({
return;
}

this.logDebug(4, "Aborting local pending job: " + stub.id + ": " + stub.reason, job);
this.logDebug(4, "Aborting local pending job: " + stub.id + ": " + stub.reason, this.safeJobLog(job));
job.abort_reason = stub.reason;

// determine if job needs to be 'finished' (i.e. aborted in retry delay)
Expand All @@ -1040,7 +1045,7 @@ module.exports = Class.create({

var worker = this.kids[job.pid] || {};

this.logDebug(4, "Aborting local job: " + stub.id + ": " + stub.reason, job);
this.logDebug(4, "Aborting local job: " + stub.id + ": " + stub.reason, this.safeJobLog(job));
job.abort_reason = stub.reason;

if (worker.child) {
Expand Down Expand Up @@ -1110,7 +1115,7 @@ module.exports = Class.create({

job.complete = 1;

this.logDebug(5, "Job completed " + (job.code ? "with error" : "successfully"), job);
this.logDebug(5, "Job completed " + (job.code ? "with error" : "successfully"), this.safeJobLog(job));

// kill completion timer, if set
var worker = this.kids[job.pid] || {};
Expand Down Expand Up @@ -1368,10 +1373,10 @@ module.exports = Class.create({

// log success or failure
if (job.code == 0) {
this.logTransaction('job', "Job completed successfully: " + job.id, job);
this.logTransaction('job', "Job completed successfully: " + job.id, this.safeJobLog(job));
}
else {
this.logError('job', "Job failed: " + job.id, job);
this.logError('job', "Job failed: " + job.id, this.safeJobLog(job));
}

// store latest job result in event state
Expand Down

0 comments on commit c45c55b

Please sign in to comment.