Skip to content

Commit 3fd26a3

Browse files
improvement(logs): print graph summary at end of graph solve (#7832)
Co-authored-by: Jon Edvald <edvald@gmail.com>
1 parent 4e052c5 commit 3fd26a3

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

core/src/graph/solver.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
120120
let lastStatus: string
121121

122122
const log = this.log
123+
// Don't want the graph-solver section to be printed for the status log
124+
const statusLog = this.log.root.createLog()
125+
123126
// TODO-0.13.1+: remove this lock and test with concurrent execution
124127
return this.lock.acquire("solve", async () => {
125128
const output = await new Promise<SolveResult>((resolve, reject) => {
@@ -203,8 +206,18 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
203206
const cleanup = ({ error }: { error: GraphResultError | null }) => {
204207
// TODO: abort remaining pending tasks?
205208
aborted = true
206-
delete this.requestedTasks[batchId]
207209
this.off("abort", cleanup)
210+
211+
// Print the final status
212+
if (logProgressStatus) {
213+
const duration = formatDuration({
214+
seconds: Math.round((new Date().getTime() - startTime.getTime()) / 1000),
215+
})
216+
const { status } = this.renderStatus(batchId, startTime, `Results after completion (took ${duration})`)
217+
statusLog.info({ msg: "\n" + status + "\n" })
218+
}
219+
220+
delete this.requestedTasks[batchId]
208221
if (error) {
209222
reject(error)
210223
}
@@ -215,8 +228,6 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
215228
this.start()
216229

217230
if (logProgressStatus) {
218-
// Don't want the graph-solver section to be printed
219-
const statusLog = this.log.root.createLog()
220231
const reportHandler = () => {
221232
const { status, content } = this.renderStatus(batchId, startTime)
222233
if (lastStatus === content) {
@@ -284,7 +295,7 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
284295
// TODO-0.13.1: currently a no-op, possibly not necessary
285296
}
286297

287-
private renderStatus(batchId: string, startTime: Date) {
298+
private renderStatus(batchId: string, startTime: Date, title?: string) {
288299
const requested = Object.values(this.requestedTasks[batchId]).sort((a, b) => {
289300
// Sort by key in ascending order
290301
return a.getKey().localeCompare(b.getKey())
@@ -332,7 +343,7 @@ export class GraphSolver extends TypedEventEmitter<SolverEvents> {
332343
const status = [
333344
renderDivider({
334345
color: chalk.magenta,
335-
title: `Graph status after ${duration}:`,
346+
title: title ?? `Graph status after ${duration}`,
336347
}),
337348
...content,
338349
renderDivider({

0 commit comments

Comments
 (0)