Commit 9d30a09d authored by Cédric Moreau's avatar Cédric Moreau

[enh] `sync`: also broadcast peers + sandbox progress through events

parent 83b7b202
Pipeline #3809 waiting for manual action with stages
in 30 minutes and 18 seconds
......@@ -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)
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment