Skip to content

Commit

Permalink
improvement: add error handler callback to podRunner log streams (#6339)
Browse files Browse the repository at this point in the history
  • Loading branch information
twelvemo authored Aug 1, 2024
1 parent e852000 commit c045254
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions core/src/plugins/kubernetes/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,28 +907,35 @@ export class PodRunner {
}

const stream = new Stream<RunLogEntry>()
void stream.forEach((entry) => {
const { msg, timestamp } = entry
let isoTimestamp: string
try {
if (timestamp) {
isoTimestamp = timestamp.toISOString()
} else {
void stream.forEach(
(entry) => {
const { msg, timestamp } = entry
let isoTimestamp: string
try {
if (timestamp) {
isoTimestamp = timestamp.toISOString()
} else {
isoTimestamp = new Date().toISOString()
}
} catch {
isoTimestamp = new Date().toISOString()
}
} catch {
isoTimestamp = new Date().toISOString()
}
events.emit("log", {
level: "verbose",
timestamp: isoTimestamp,
msg,
...logEventContext,
})
if (tty) {
process.stdout.write(`${entry.msg}\n`)
events.emit("log", {
level: "verbose",
timestamp: isoTimestamp,
msg,
...logEventContext,
})
if (tty) {
process.stdout.write(`${entry.msg}\n`)
}
},
(err) => {
if (err) {
log.error(`Error while following logs: ${err}`)
}
}
})
)
return new K8sLogFollower({
defaultNamespace: this.namespace,
// We use 1 second in the PodRunner, because the task / test will only finish once the LogFollower finished.
Expand Down

0 comments on commit c045254

Please sign in to comment.