Commit dd6a4f0d authored by Éloïs's avatar Éloïs

Merge branch 'feature/sync-duration' into dev

parents 1affed5f 65fe5616
......@@ -140,6 +140,7 @@ export class Synchroniser extends stream.Duplex {
this.logger.info("Sync started.");
const fullSync = !to;
const syncStartTime = Date.now();
//============
// Blockchain headers
......@@ -240,9 +241,10 @@ export class Synchroniser extends stream.Duplex {
await this.syncStrategy.syncPeers(fullSync, to);
}
this.watcher.end();
const syncDuration = Date.now() - syncStartTime;
this.watcher.end(syncDuration);
this.push({ sync: true });
this.logger.info("Sync finished.");
this.logger.info("Sync finished (duration %s ms).", syncDuration);
} catch (err) {
this.push({ sync: false, msg: err });
err &&
......
......@@ -11,7 +11,7 @@ export interface Watcher {
appliedPercent(pct?: number): number;
sbxPercent(pct?: number): number;
peersPercent(pct?: number): number;
end(): void;
end(duration?: number): void;
reserveNodes(nodesAvailable: P2pCandidate[]): void;
......@@ -114,8 +114,8 @@ export class EventWatcher extends events.EventEmitter implements Watcher {
return method(pct);
}
end(): void {
this.innerWatcher.end();
end(syncDuration?: number): void {
this.innerWatcher.end(syncDuration);
}
onEvent(e: EventName, cb: (pct: number) => void) {
......@@ -261,8 +261,14 @@ export class MultimeterWatcher implements Watcher {
return 0;
}
end() {
this.multi.write("\nAll done.\n");
end(duration?: number) {
if (duration) {
const durationSecs = Math.floor(duration / 1000);
const durationMillisRemain = duration % 1000;
this.multi.write("\nAll done in " + durationSecs + "." + durationMillisRemain + " seconds.\n");
} else {
this.multi.write("\nAll done.\n");
}
this.multi.destroy();
}
......
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