From c45c55b4e438acba1d3039a3b56f6387e830d4e5 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 26 Oct 2023 16:28:39 -0400 Subject: [PATCH] job logging update --- lib/api/event.js | 7 ++++++- lib/job.js | 17 +++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/api/event.js b/lib/api/event.js index 16ee430..ff60ee9 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -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; @@ -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) { diff --git a/lib/job.js b/lib/job.js index 6df90db..f19740b 100644 --- a/lib/job.js +++ b/lib/job.js @@ -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; @@ -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) @@ -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) @@ -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) { @@ -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] || {}; @@ -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