refactor storage module

This commit is contained in:
Iuri Matias 2018-06-01 12:53:23 -04:00
parent eadbeb0498
commit 60c687aa41
2 changed files with 30 additions and 44 deletions

View File

@ -155,59 +155,45 @@ class Storage {
this._embark.addProviderInit('storage', code, shouldInit); this._embark.addProviderInit('storage', code, shouldInit);
} }
checkStorageService(platform, url, callback) {
const self = this;
const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{url}}.', {platform: platform, url: url})};
// start the upload storage node
self._checkStorageEndpoint(platform, function (err) {
if (!err) {
return callback();
}
self._startStorageNode(platform, (err) => {
if (err) {
self._logger.error(err);
return callback(errorObj);
}
// Check endpoint again to see if really did start
self._checkStorageEndpoint(platform, (err) => {
if (err) {
return callback(errorObj);
}
callback();
});
});
});
}
startStorageProcesses(){ startStorageProcesses(){
let platform = this._storageConfig.upload.provider; let platform = this._storageConfig.upload.provider;
let self = this; let self = this;
async.waterfall([ async.waterfall([
function checkStorageService(callback){ function _checkStorageService(callback){
const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{url}}.', {platform: platform, url: utils.buildUrlFromConfig(self._storageConfig.upload)})}; self.checkStorageService(platform, utils.buildUrlFromConfig(self._storageConfig.upload), callback);
// start the upload storage node
self._checkStorageEndpoint(platform, function (err) {
if (!err) {
return callback();
}
self._startStorageNode(platform, (err) => {
if (err) {
self._logger.error(err);
return callback(errorObj);
}
// Check endpoint again to see if really did start
self._checkStorageEndpoint(platform, (err) => {
if (err) {
return callback(errorObj);
}
callback();
});
});
});
}, },
function checkDappConnectionStorageService(callback){ function checkDappConnectionStorageService(callback){
// start any dappConnection storage nodes // start any dappConnection storage nodes
self._validDappProviders.forEach(dappConn => { self._validDappProviders.forEach(dappConn => {
if(!dappConn.provider || dappConn.provider === platform) return; // don't start the process we've just started above if(!dappConn.provider || dappConn.provider === platform) return; // don't start the process we've just started above
const errorObj = {message: __('Cannot start {{platform}} node on {{url}}.', {platform: dappConn.provider, url: utils.buildUrlFromConfig(dappConn)})}; self.checkStorageService(dappConn.provider, utils.buildUrlFromConfig(dappConn), callback);
self._checkStorageEndpoint(dappConn.provider, function (err) {
if (!err) {
return callback();
}
self._startStorageNode(dappConn.provider, (err) => {
if (err) {
self._logger.error(err);
return callback(errorObj);
}
// Check endpoint again to see if really did start
self._checkStorageEndpoint(dappConn.provider, (err) => {
if (err) {
return callback(errorObj);
}
callback();
});
});
});
}); });
} }
]); ]);

View File

@ -36,4 +36,4 @@
"getUrl": "https://ipfs.infura.io/ipfs/" "getUrl": "https://ipfs.infura.io/ipfs/"
} }
} }
} }