Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
improve logging and update run script for restoring monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-paulo-parity committed Sep 2, 2021
1 parent 11b9240 commit f038acf
Show file tree
Hide file tree
Showing 3 changed files with 316 additions and 168 deletions.
55 changes: 27 additions & 28 deletions bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function errorResult(message, error) {
}

let cwd = process.cwd();
console.log(`process cwd: ${cwd}`);

const Mutex = require('async-mutex').Mutex;
const mutex = new Mutex();
Expand All @@ -21,38 +20,43 @@ function BenchContext(app, config) {

self.runTask = async function(cmd, { title, shouldLogOutput } = {}) {
if (title) {
app.log(title)
app.log({ title, msg: `Running task on directory ${process.cwd()}` })
}

let stdout = "", stderr = "", error = false

try {
if (shouldLogOutput) {
console.log(`<=== Start command output (cwd: ${process.cwd()})`)
}

await new Promise(function (resolve) {
const proc = cp.spawn("/bin/bash", ["-c", cmd], { stdio: "pipe" })

proc.stdout.on("data", function (data) {
data = data.toString()

if (data && shouldLogOutput) {
console.log(data.trim())
}

stdout += data
})
const getStreamCallback = function(channel) {
return function (data) {
data = data.toString()

proc.stderr.on("data", function (data) {
data = data.toString()
if (shouldLogOutput) {
const msg = data.trim()
if (msg) {
app.log({ msg, channel })
}
}

if (data && shouldLogOutput) {
console.log(data.trim())
switch (channel) {
case "stderr": {
stderr += data
break
}
case "stdout": {
stdout += data
break
}
default: {
throw new Error(`Got unexpected process channel ${channel}`)
}
}
}

stderr += data
})
}
proc.stdout.on("data", getStreamCallback("stdout"))
proc.stderr.on("data", getStreamCallback("stderr"))

proc.on("close", function (code) {
error = !!code
Expand All @@ -65,12 +69,7 @@ function BenchContext(app, config) {
stdout = err.stdout.toString()
stderr = err.stderr.toString()
} else {
app.log.error("Caught exception in command execution")
app.log.error(err)
}
} finally {
if (shouldLogOutput) {
console.log("===> Finished command output")
app.log.fatal({ msg: "Caught exception in command execution", err })
}
}

Expand Down
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const githubCommentLimitLength = 65536
const githubCommentLimitTruncateMessage = "<truncated>..."

module.exports = (app) => {
for (const event of ["uncaughtException", "unhandledRejection"]) {
process.on(event, function (error, origin) {
app.log.fatal({ event, error, origin })
process.exit(1)
})
}

const baseBranch = process.env.BASE_BRANCH || "master"
app.log.debug(`base branch: ${baseBranch}`)

Expand Down Expand Up @@ -54,10 +61,7 @@ module.exports = (app) => {

const getPushDomain = async function () {
const token = (
await authInstallation({
type: "installation",
installationId,
})
await authInstallation({ type: "installation", installationId })
).token

const url = `https://x-access-token:${token}@github.com`
Expand Down Expand Up @@ -169,7 +173,13 @@ ${extraInfo}
body,
})
} catch (error) {
app.log.error(error)
app.log.fatal({
error,
repo,
owner,
pull_number,
msg: "Caught exception in issue_comment's handler",
})
await context.octokit.issues.createComment(
context.issue({
body: `Exception caught: \`${error.message}\`\n${error.stack}`,
Expand Down
Loading

0 comments on commit f038acf

Please sign in to comment.