From 54c5f4f83ec2c48fa874f6c7c63f7fd8dea841e2 Mon Sep 17 00:00:00 2001 From: David de Boer Date: Wed, 10 Jul 2024 12:46:03 +0200 Subject: [PATCH] fix: Import progress --- jest.config.js | 6 +++--- src/pipeline.ts | 19 ++++++++++++------- src/stage.ts | 3 ++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/jest.config.js b/jest.config.js index 5896089..f25faf0 100644 --- a/jest.config.js +++ b/jest.config.js @@ -11,10 +11,10 @@ export default { coverageReporters: ['json-summary', 'text'], coverageThreshold: { global: { - lines: 70.9, - statements: 71.01, + lines: 70.65, + statements: 70.77, branches: 66.66, - functions: 76.59, + functions: 76.05, }, }, transform: { diff --git a/src/pipeline.ts b/src/pipeline.ts index 4e6088e..0b5958c 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -222,7 +222,7 @@ class Pipeline { ); resolve(); }); - this.monitorImport(stage, progress); + this.monitorImport(stage); try { stage.run(); } catch (e) { @@ -249,18 +249,19 @@ class Pipeline { ); } - private monitorImport(stage: Stage, progress: Progress) { - let importStartTime: number; + private monitorImport(stage: Stage) { + let progress: Progress; stage.on('importStart', () => { - progress.start('Importing data to SPARQL store'); - importStartTime = performance.now(); + progress = new Progress({silent: this.opts?.silent === true}).start( + 'Importing data to SPARQL store' + ); }); stage.on('imported', numOfTriples => { progress.text( `Importing data to SPARQL store\n\n Statements: ${millify( numOfTriples - )}\n Duration: ${formatDuration(importStartTime, performance.now())} ` + )}\n Duration: ${formatDuration(progress.startTime, performance.now())} ` ); }); stage.on('importSuccess', numOfTriples => { @@ -268,10 +269,14 @@ class Pipeline { `Imported ${millify( numOfTriples )} statements to SPARQL store (took ${prettyMilliseconds( - performance.now() - importStartTime + performance.now() - progress.startTime )})` ); }); + stage.on('importError', e => { + progress?.fail('Import failed'); + this.error(e); + }); } private async writeResult(): Promise { diff --git a/src/stage.ts b/src/stage.ts index 84ae9c9..13970af 100644 --- a/src/stage.ts +++ b/src/stage.ts @@ -23,6 +23,7 @@ interface Events { end: [iteratorCount: number, statements: number]; iteratorResult: [$this: NamedNode, quadsGenerated: number]; error: [Error]; + importError: [Error]; } export default class Stage extends EventEmitter { @@ -105,7 +106,7 @@ export default class Stage extends EventEmitter { try { await this.importer.run(); } catch (e) { - this.emit('error', e as Error); + this.emit('importError', e as Error); return; } }