Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
improve logging and update run script for restoring monitoring
  • Loading branch information
joao-paulo-parity committed Sep 2, 2021
commit f038acfde9fe1ec80ddb2e387ad658df97146491
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