Skip to content

Commit

Permalink
fix: Import progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ddeboer committed Jul 10, 2024
1 parent a702c96 commit 3e5c5d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default class Generator extends EventEmitter<Events> {
}

public async run($this: NamedNode): Promise<void> {
// console.log('IRI iterated only once:', $this.value);
// Prevent duplicates from added to $thisList, but immediately run any query that is batched.
this.$thisList.push($this);
this.iterationsIncoming++;
Expand Down
19 changes: 12 additions & 7 deletions src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Pipeline {
);
resolve();
});
this.monitorImport(stage, progress);
this.monitorImport(stage);
try {
stage.run();
} catch (e) {
Expand All @@ -249,29 +249,34 @@ 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 => {
progress.succeed(
`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<void> {
Expand Down
3 changes: 2 additions & 1 deletion src/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Events> {
Expand Down Expand Up @@ -105,7 +106,7 @@ export default class Stage extends EventEmitter<Events> {
try {
await this.importer.run();
} catch (e) {
this.emit('error', e as Error);
this.emit('importError', e as Error);
return;
}
}
Expand Down

0 comments on commit 3e5c5d3

Please sign in to comment.