Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Import progress #101

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
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