fix(embark/storage): fix hang when storage is disabled

This commit is contained in:
Jonathan Rainville 2019-03-14 09:57:48 -04:00 committed by Iuri Matias
parent 4d424c06b9
commit 5e4a80edec
4 changed files with 43 additions and 29 deletions

View File

@ -192,7 +192,7 @@ class Engine {
this.registerModule('code_generator', {plugins: self.plugins, env: self.env});
const generateCode = function (modifiedAssets) {
self.events.request("module:storage:initiated", () => {
self.events.request("module:storage:onReady", () => {
self.events.request("code-generator:embarkjs:build", () => {
self.events.emit('code-generator-ready', modifiedAssets);
});
@ -278,15 +278,15 @@ class Engine {
if (!this.config.storageConfig.available_providers.includes("ipfs")) {
return next();
}
this.registerModule('ipfs');
this.events.on("ipfs:process:started", next);
this.registerModule('ipfs');
},
(next) => {
if (!this.config.storageConfig.available_providers.includes("swarm")) {
return next();
}
this.registerModule('swarm');
this.events.on("swarm:process:started", next);
this.registerModule('swarm');
}
], (err) => {
if(err) {

View File

@ -20,29 +20,31 @@ class IPFS {
this.webServerConfig = embark.config.webServerConfig;
this.blockchainConfig = embark.config.blockchainConfig;
if (this.isIpfsStorageEnabledInTheConfig()) {
this.setServiceCheck();
this.registerUploadCommand();
this.events.request("processes:register", "ipfs", (cb) => {
this.startProcess(() => {
this.addStorageProviderToEmbarkJS();
this.addObjectToConsole();
this.events.emit("ipfs:process:started");
cb();
});
});
this._checkService((err) => {
if (!err) {
return;
}
this.logger.info("IPFS node not found, attempting to start own node");
this.listenToCommands();
this.registerConsoleCommands();
this.events.request('processes:launch', 'ipfs');
});
if (!this.isIpfsStorageEnabledInTheConfig()) {
return this.events.emit("ipfs:process:started", false);
}
this.setServiceCheck();
this.registerUploadCommand();
this.events.request("processes:register", "ipfs", (cb) => {
this.startProcess(() => {
this.addStorageProviderToEmbarkJS();
this.addObjectToConsole();
this.events.emit("ipfs:process:started");
cb();
});
});
this._checkService((err) => {
if (!err) {
return;
}
this.logger.info("IPFS node not found, attempting to start own node");
this.listenToCommands();
this.registerConsoleCommands();
this.events.request('processes:launch', 'ipfs');
});
}
downloadIpfsApi(cb) {

View File

@ -3,12 +3,24 @@ class Storage {
this.embark = embark;
this.storageConfig = embark.config.storageConfig;
this.plugins = options.plugins;
this.ready = false;
if (!this.storageConfig.enabled) return;
this.embark.events.setCommandHandler("module:storage:onReady", (cb) => {
if (this.ready) {
return cb();
}
this.embark.events.once("module:storage:ready", cb);
});
if (!this.storageConfig.enabled) {
this.ready = true;
return;
}
this.handleUploadCommand();
this.addSetProviders(() => {
this.embark.events.setCommandHandler("module:storage:initiated", (cb) => { cb(); });
this.ready = true;
this.embark.events.emit("module:storage:ready");
});
}

View File

@ -26,7 +26,7 @@ class Swarm {
if (this.isSwarmEnabledInTheConfig() && cantDetermineUrl) {
console.warn('\n===== Swarm module will not be loaded =====');
console.warn(`Swarm is enabled in the config, however the config is not setup to provide a URL for swarm and therefore the Swarm module will not be loaded. Please either change the ${'config/storage > upload'.bold} setting to Swarm or add the Swarm config to the ${'config/storage > dappConnection'.bold} array. Please see ${'https://embark.status.im/docs/storage_configuration.html'.underline} for more information.\n`);
return;
return this.events.emit("swarm:process:started", false);
}
if (!this.isSwarmEnabledInTheConfig()) {
this.embark.registerConsoleCommand({
@ -36,7 +36,7 @@ class Swarm {
cb();
}
});
return;
return this.events.emit("swarm:process:started", false);
}
this.providerUrl = utils.buildUrl(this.storageConfig.upload.protocol, this.storageConfig.upload.host, this.storageConfig.upload.port);