Progress bar adjustment.

This commit is contained in:
k 2017-04-21 14:33:40 -04:00
parent 9a7b39230f
commit cef4088908
2 changed files with 14 additions and 12 deletions

View File

@ -160,7 +160,6 @@ DB.prototype.start = function(callback) {
});
self._sync.on('synced', function() {
log.permitWrites = true;
log.info('Initial sync complete');
});
@ -169,8 +168,6 @@ DB.prototype.start = function(callback) {
});
self.node.once('ready', function() {
log.permitWrites = false;
self._sync.initialSync();
self.node.services.bitcoind.on('tip', function(height) {

View File

@ -8,6 +8,8 @@ var async = require('async');
var bitcore = require('bitcore-lib');
var BufferUtil = bitcore.util.buffer;
var ProgressBar = require('progress');
var index = require('../../index');
var log = index.log;
var green = '\u001b[42m \u001b[0m';
var red = '\u001b[41m \u001b[0m';
@ -98,6 +100,7 @@ Sync.prototype.initialSync = function() {
.pipe(processSerial);
self.lastReportedBlock = self.db.tip.__height;
self.progressBar = new ProgressBar('[:bar] :percent :current blks, :blockspersec blks/sec, :elapsed secs', {
complete: green,
incomplete: red,
@ -105,15 +108,7 @@ Sync.prototype.initialSync = function() {
clear: true
});
self.progressBar.tick(self.db.tip.__height, {
blockspersec: 0
});
var timer = setInterval(function () {
var tick = self.db.tip.__height - self.lastReportedBlock;
self.progressBar.tick(tick, { blockspersec: tick });
self.lastReportedBlock = self.db.tip.__height;
}, 1000);
var timer = setInterval(self.reportStatus.bind(this), 1000);
processSerial.on('finish', function() {
self.syncing = false;
@ -128,6 +123,16 @@ Sync.prototype.initialSync = function() {
};
Sync.prototype.reportStatus = function() {
if (process.stderr.isTTY) {
var tick = this.db.tip.__height - this.lastReportedBlock;
this.progressBar.tick(tick, { blockspersec: tick });
this.lastReportedBlock = this.db.tip.__height;
} else {
log.info('Sync: current height is: ' + this.db.tip.__height);
}
};
Sync.prototype.sync = function() {
var self = this;
if(this.syncing || this.db.reorg) {