diff --git a/app/modules/crawler/lib/sync.ts b/app/modules/crawler/lib/sync.ts index a4b055f9249c917d798c854881f97c46dd54e966..9d0fa1f51886db1b43604130557938df1476e2db 100644 --- a/app/modules/crawler/lib/sync.ts +++ b/app/modules/crawler/lib/sync.ts @@ -43,11 +43,11 @@ export class Synchroniser extends stream.Duplex { // Wrapper to also push event stream this.watcher = new EventWatcher(interactive ? new MultimeterWatcher() : new LoggerWatcher(this.logger)) - this.watcher.onEvent('downloadChange', (pct: number) => this.push({ download: pct })) - this.watcher.onEvent('storageChange', (pct: number) => this.push({ saved: pct })) - this.watcher.onEvent('appliedChange', (pct: number) => this.push({ applied: pct })) - this.watcher.onEvent('sbxChange', (pct: number) => this.push({ sandbox: pct })) - this.watcher.onEvent('peersChange', (pct: number) => this.push({ peersSync: pct })) + this.watcher.onEvent('downloadChange', () => this.push(this.watcher.getStats())) + this.watcher.onEvent('storageChange', () => this.push(this.watcher.getStats())) + this.watcher.onEvent('appliedChange', () => this.push(this.watcher.getStats())) + this.watcher.onEvent('sbxChange', () => this.push(this.watcher.getStats())) + this.watcher.onEvent('peersChange', () => this.push(this.watcher.getStats())) this.syncStrategy.setWatcher(this.watcher) diff --git a/app/modules/crawler/lib/sync/Watcher.ts b/app/modules/crawler/lib/sync/Watcher.ts index 77da032b5c70c24a15081d1340bbd673d5e868fd..bbb5f113ea3b4679b1e2bfe57c86add88c62f7a1 100644 --- a/app/modules/crawler/lib/sync/Watcher.ts +++ b/app/modules/crawler/lib/sync/Watcher.ts @@ -59,6 +59,16 @@ export class EventWatcher extends events.EventEmitter implements Watcher { onEvent(e: EventName, cb: (pct: number) => void) { this.on(e, cb) } + + getStats() { + return { + download: this.downloadPercent(), + saved: this.storagePercent(), + applied: this.appliedPercent(), + sandbox: this.sbxPercent(), + peersSync: this.peersPercent(), + } + } } export class MultimeterWatcher implements Watcher { @@ -173,6 +183,8 @@ export class LoggerWatcher implements Watcher { private downPct = 0 private savedPct = 0 private appliedPct = 0 + private sbxPct = 0 + private peersPct = 0 private lastMsg = "" constructor(private logger:any) { @@ -202,11 +214,17 @@ export class LoggerWatcher implements Watcher { } sbxPercent(pct:number) { - return 0 + if (pct > this.sbxPct) { + this.sbxPct = pct + } + return this.sbxPct } peersPercent(pct:number) { - return 0 + if (pct > this.peersPct) { + this.peersPct = pct + } + return this.peersPct } change(prop: 'downPct'|'savedPct'|'appliedPct', pct:number) {