fix start process

This commit is contained in:
Iuri Matias 2018-07-07 19:29:04 +03:00
parent cd6927c353
commit 651ef31bb5
3 changed files with 76 additions and 25 deletions

View File

@ -3,6 +3,7 @@ const utils = require('../../utils/utils.js');
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const IpfsApi = require('ipfs-api'); const IpfsApi = require('ipfs-api');
const _ = require('underscore'); const _ = require('underscore');
const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher');
class IPFS { class IPFS {
@ -15,6 +16,15 @@ class IPFS {
this.port = options.port || this.storageConfig.upload.port; this.port = options.port || this.storageConfig.upload.port;
this.protocol = options.protocol || this.storageConfig.upload.protocol; this.protocol = options.protocol || this.storageConfig.upload.protocol;
this.embark = embark; this.embark = embark;
this.webServerConfig = embark.config.webServerConfig,
this.blockchainConfig = embark.config.blockchainConfig
this.commandlineDeploy();
this.setServiceCheck();
this.addProviderToEmbarkJS();
this.addObjectToConsole();
this.startProcess(() => {});
} }
commandlineDeploy() { commandlineDeploy() {
@ -102,6 +112,24 @@ class IPFS {
this.events.emit("runcode:register", "ipfs", ipfs); this.events.emit("runcode:register", "ipfs", ipfs);
} }
startProcess(callback) {
let self = this;
const storageProcessesLauncher = new StorageProcessesLauncher({
logger: self.logger,
events: self.events,
storageConfig: self.storageConfig,
webServerConfig: self.webServerConfig,
blockchainConfig: self.blockchainConfig
});
self.logger.trace(`Storage module: Launching ipfs process...`);
return storageProcessesLauncher.launchProcess('ipfs', (err) => {
if (err) {
return callback(err);
}
callback();
});
}
} }
module.exports = IPFS; module.exports = IPFS;

View File

@ -6,6 +6,9 @@ const async = require('async');
const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher'); const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher');
const constants = require('../../constants'); const constants = require('../../constants');
const IpfsModule = require('../ipfs');
const SwarmModule = require('../swarm');
class Storage { class Storage {
constructor(embark, options){ constructor(embark, options){
const self = this; const self = this;
@ -18,22 +21,25 @@ class Storage {
this._events = options.events; this._events = options.events;
this._logger = options.logger; this._logger = options.logger;
if(!this._storageConfig.enabled) return; if (!this._storageConfig.enabled) return;
// filter list of dapp connections based on available_providers set in config // // filter list of dapp connections based on available_providers set in config
let hasSwarm = _.contains(this._storageConfig.available_providers, 'swarm'); // don't need to eval this in every loop iteration // let hasSwarm = _.contains(this._storageConfig.available_providers, 'swarm'); // don't need to eval this in every loop iteration
// contains valid dapp storage providers // // contains valid dapp storage providers
this._validDappProviders = _.filter(this._storageConfig.dappConnection, (conn) => { // this._validDappProviders = _.filter(this._storageConfig.dappConnection, (conn) => {
return _.contains(this._storageConfig.available_providers, conn.provider) || (conn === '$BZZ' && hasSwarm); // return _.contains(this._storageConfig.available_providers, conn.provider) || (conn === '$BZZ' && hasSwarm);
}); // });
this.initStorageForEmbark(); // this.initStorageForEmbark();
this.initStorageForDapp(); // this.initStorageForDapp();
// don't start storage processes on build command, only on upload or run // // don't start storage processes on build command, only on upload or run
if(_.contains(options.context, constants.contexts.upload) || _.contains(options.context, constants.contexts.run)){ // if(_.contains(options.context, constants.contexts.upload) || _.contains(options.context, constants.contexts.run)){
this.startStorageProcesses(); // this.startStorageProcesses();
} // }
new IpfsModule(embark, options); /*eslint no-new: "off"*/
new SwarmModule(embark, options); /*eslint no-new: "off"*/
embark.events.setCommandHandler('storage:upload', (cb) => { embark.events.setCommandHandler('storage:upload', (cb) => {
let platform = options.storageConfig.upload.provider; let platform = options.storageConfig.upload.provider;
@ -86,16 +92,6 @@ class Storage {
}); });
} }
/// Initializes a storage provider for Embark upload
initStorageForEmbark(){
let storageProviderCls = require(`../${this._storageConfig.upload.provider}/index.js`);
let uploadProvider = new storageProviderCls(this._embark, this._options); /*eslint no-new: "off"*/
if(typeof uploadProvider.commandlineDeploy == 'function') uploadProvider.commandlineDeploy();
if(typeof uploadProvider.setServiceCheck == 'function') uploadProvider.setServiceCheck();
if(typeof uploadProvider.addObjectToConsole == 'function') uploadProvider.addObjectToConsole();
}
/** /**
* Initializes a storage provider for EmbarkJS * Initializes a storage provider for EmbarkJS
* *
@ -137,7 +133,6 @@ class Storage {
* @returns {void} * @returns {void}
*/ */
addSetProviders() { addSetProviders() {
let code = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this._validDappProviders)});`; let code = `\nEmbarkJS.Storage.setProviders(${JSON.stringify(this._validDappProviders)});`;
let shouldInit = (storageConfig) => { let shouldInit = (storageConfig) => {
return (this._validDappProviders !== undefined && this._validDappProviders.length > 0 && storageConfig.enabled === true); return (this._validDappProviders !== undefined && this._validDappProviders.length > 0 && storageConfig.enabled === true);

View File

@ -3,6 +3,7 @@ const utils = require('../../utils/utils.js');
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const Web3Bzz = require('web3-bzz'); const Web3Bzz = require('web3-bzz');
const _ = require('underscore'); const _ = require('underscore');
const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher');
class Swarm { class Swarm {
@ -15,11 +16,19 @@ class Swarm {
this.port = options.port || this.storageConfig.port; this.port = options.port || this.storageConfig.port;
this.embark = embark; this.embark = embark;
this.webServerConfig = embark.config.webServerConfig,
this.blockchainConfig = embark.config.blockchainConfig
this.providerUrl = utils.buildUrl(options.protocol || options.storageConfig.upload.protocol, options.host || options.storageConfig.upload.host, options.port || options.storageConfig.upload.port); this.providerUrl = utils.buildUrl(options.protocol || options.storageConfig.upload.protocol, options.host || options.storageConfig.upload.host, options.port || options.storageConfig.upload.port);
this.getUrl = options.storageConfig.upload.getUrl || this.providerUrl + '/bzz:/'; this.getUrl = options.storageConfig.upload.getUrl || this.providerUrl + '/bzz:/';
this.bzz = new Web3Bzz(this.providerUrl); this.bzz = new Web3Bzz(this.providerUrl);
this.commandlineDeploy();
this.setServiceCheck();
this.addProviderToEmbarkJS();
this.startProcess(() => {});
} }
commandlineDeploy() { commandlineDeploy() {
@ -81,6 +90,25 @@ class Swarm {
this.embark.addCodeToEmbarkJS(code); this.embark.addCodeToEmbarkJS(code);
} }
startProcess(callback) {
let self = this;
const storageProcessesLauncher = new StorageProcessesLauncher({
logger: self.logger,
events: self.events,
storageConfig: self.storageConfig,
webServerConfig: self.webServerConfig,
blockchainConfig: self.blockchainConfig
});
self.logger.trace(`Storage module: Launching swarm process...`);
return storageProcessesLauncher.launchProcess('swarm', (err) => {
if (err) {
return callback(err);
}
callback();
});
}
} }
module.exports = Swarm; module.exports = Swarm;