report wwritten rows

This commit is contained in:
SPRINX0\prochazka
2025-03-04 15:08:24 +01:00
parent 3bf22a8606
commit bffc34485a
6 changed files with 66 additions and 4 deletions

View File

@@ -0,0 +1,45 @@
export class RowProgressReporter {
counter = 0;
timeoutHandle = null;
constructor(public progressName, public field = 'writtenRowCount') {}
add(count: number) {
this.counter += count;
if (!this.progressName) {
return;
}
if (this.timeoutHandle) {
return;
}
this.timeoutHandle = setTimeout(() => {
this.timeoutHandle = null;
this.send();
}, 1000);
}
finish() {
if (!this.progressName) {
return;
}
if (this.timeoutHandle) {
clearTimeout(this.timeoutHandle);
this.timeoutHandle = null;
}
this.send();
}
send() {
if (!this.progressName) {
return;
}
process.send({
msgtype: 'progress',
progressName: this.progressName,
[this.field]: this.counter,
});
}
}