check swarm connection before attempting to connect

This commit is contained in:
Iuri Matias 2018-07-07 20:56:34 +03:00
parent 513659a53e
commit 7a612ea5df
1 changed files with 21 additions and 6 deletions

View File

@ -29,6 +29,14 @@ class Swarm {
this.setServiceCheck();
this.addProviderToEmbarkJS();
this.startProcess(() => {});
this._checkService((err) => {
if (!err) {
return;
}
self.logger.info("Swarm node not found, attempting to start own node");
self.startProcess(() => {});
});
}
commandlineDeploy() {
@ -64,16 +72,23 @@ class Swarm {
self.events.request("services:register", 'Swarm', function(cb){
self.logger.trace(`Checking Swarm availability on ${self.bzz.currentProvider}...`);
self.bzz.isAvailable().then(result => {
self.logger.trace("Swarm " + (result ? '':'un') + "available");
return cb({name: "Swarm ", status: result ? 'on':'off'});
}).catch(err => {
self._checkService((err, result) => {
if (err) {
self.logger.trace("Check Swarm availability error: " + err);
return cb({name: "Swarm ", status: 'off'});
}
self.logger.trace("Swarm " + (result ? '':'on') + "available");
return cb({name: "Swarm ", status: result ? 'on':'off'});
});
});
}
_checkService(cb) {
this.bzz.isAvailable().then(result => {
cb(null, result);
}).catch(cb);
}
addProviderToEmbarkJS() {
// TODO: make this a shouldAdd condition
if (this.storageConfig === {}) {