sync retry after RPC error
This commit is contained in:
parent
3da2254541
commit
1e9307f4a0
|
@ -8,7 +8,7 @@ lib-cov
|
||||||
*.pid
|
*.pid
|
||||||
*.gz
|
*.gz
|
||||||
*.swp
|
*.swp
|
||||||
|
tags
|
||||||
pids
|
pids
|
||||||
logs
|
logs
|
||||||
results
|
results
|
||||||
|
@ -23,7 +23,6 @@ node_modules
|
||||||
peerdb.json
|
peerdb.json
|
||||||
|
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
node_modules
|
|
||||||
.nodemonignore
|
.nodemonignore
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
45
lib/Sync.js
45
lib/Sync.js
|
@ -199,19 +199,35 @@ function spec() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync.prototype.init = function(opts) {
|
Sync.prototype.init = function(opts) {
|
||||||
if (!(opts && opts.skip_db_connection)) {
|
|
||||||
mongoose.connect(config.db);
|
|
||||||
}
|
|
||||||
this.db = mongoose.connection;
|
|
||||||
this.rpc = new RpcClient(config.bitcoind);
|
this.rpc = new RpcClient(config.bitcoind);
|
||||||
|
|
||||||
this.db.on('error', console.error.bind(console, 'connection error:'));
|
|
||||||
|
if (!(opts && opts.skip_db_connection)) {
|
||||||
|
mongoose.connect(config.db, {server: {auto_reconnect: true}} );
|
||||||
|
}
|
||||||
|
|
||||||
|
this.db = mongoose.connection;
|
||||||
|
|
||||||
|
this.db.on('error', function(err) {
|
||||||
|
console.log('connection error:' + err);
|
||||||
|
moogose.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.db.on('disconnect', function(err) {
|
||||||
|
console.log('disconnect:' + err);
|
||||||
|
mongoose.connect(config.db, {server: {auto_reconnect: true}} );
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync.prototype.import_history = function(opts, next) {
|
Sync.prototype.import_history = function(opts, next) {
|
||||||
|
|
||||||
var that = this;
|
var that = this;
|
||||||
|
|
||||||
|
var retry_attemps = 100;
|
||||||
|
var retry_secs = 2;
|
||||||
|
|
||||||
this.db.once('open', function() {
|
this.db.once('open', function() {
|
||||||
async.series([
|
async.series([
|
||||||
function(cb) {
|
function(cb) {
|
||||||
|
@ -240,10 +256,23 @@ function spec() {
|
||||||
},
|
},
|
||||||
|
|
||||||
function(cb) {
|
function(cb) {
|
||||||
|
function sync() {
|
||||||
|
that.syncBlocks( function(err) {
|
||||||
|
|
||||||
|
|
||||||
|
if (err && err.message.match(/ECONNREFUSED/) && retry_attemps--){
|
||||||
|
setTimeout(function() {
|
||||||
|
console.log("Retrying in %d secs ", retry_secs);
|
||||||
|
sync();
|
||||||
|
}, retry_secs * 1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return next(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!opts.skip_blocks) {
|
if (!opts.skip_blocks) {
|
||||||
that.syncBlocks( cb);
|
sync();
|
||||||
} else {
|
|
||||||
cb();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/* Exploding happens on block insertion
|
/* Exploding happens on block insertion
|
||||||
|
|
Loading…
Reference in New Issue