Skip to content
Snippets Groups Projects
Commit 65fe5616 authored by Éloïs's avatar Éloïs
Browse files

[feat] sync: print sync duration at end

parent 1affed5f
No related branches found
No related tags found
No related merge requests found
...@@ -140,6 +140,7 @@ export class Synchroniser extends stream.Duplex { ...@@ -140,6 +140,7 @@ export class Synchroniser extends stream.Duplex {
this.logger.info("Sync started."); this.logger.info("Sync started.");
const fullSync = !to; const fullSync = !to;
const syncStartTime = Date.now();
//============ //============
// Blockchain headers // Blockchain headers
...@@ -240,9 +241,10 @@ export class Synchroniser extends stream.Duplex { ...@@ -240,9 +241,10 @@ export class Synchroniser extends stream.Duplex {
await this.syncStrategy.syncPeers(fullSync, to); await this.syncStrategy.syncPeers(fullSync, to);
} }
this.watcher.end(); const syncDuration = Date.now() - syncStartTime;
this.watcher.end(syncDuration);
this.push({ sync: true }); this.push({ sync: true });
this.logger.info("Sync finished."); this.logger.info("Sync finished (duration %s ms).", syncDuration);
} catch (err) { } catch (err) {
this.push({ sync: false, msg: err }); this.push({ sync: false, msg: err });
err && err &&
......
...@@ -11,7 +11,7 @@ export interface Watcher { ...@@ -11,7 +11,7 @@ export interface Watcher {
appliedPercent(pct?: number): number; appliedPercent(pct?: number): number;
sbxPercent(pct?: number): number; sbxPercent(pct?: number): number;
peersPercent(pct?: number): number; peersPercent(pct?: number): number;
end(): void; end(duration?: number): void;
reserveNodes(nodesAvailable: P2pCandidate[]): void; reserveNodes(nodesAvailable: P2pCandidate[]): void;
...@@ -114,8 +114,8 @@ export class EventWatcher extends events.EventEmitter implements Watcher { ...@@ -114,8 +114,8 @@ export class EventWatcher extends events.EventEmitter implements Watcher {
return method(pct); return method(pct);
} }
end(): void { end(syncDuration?: number): void {
this.innerWatcher.end(); this.innerWatcher.end(syncDuration);
} }
onEvent(e: EventName, cb: (pct: number) => void) { onEvent(e: EventName, cb: (pct: number) => void) {
...@@ -261,8 +261,14 @@ export class MultimeterWatcher implements Watcher { ...@@ -261,8 +261,14 @@ export class MultimeterWatcher implements Watcher {
return 0; return 0;
} }
end() { 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.write("\nAll done.\n");
}
this.multi.destroy(); this.multi.destroy();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment