use async auto to deploy parallely

This commit is contained in:
Jonathan Rainville 2018-08-09 12:58:41 -04:00 committed by Iuri Matias
parent 19f22025ad
commit 3a621f3efd
1 changed files with 32 additions and 21 deletions

View File

@ -1,8 +1,7 @@
let async = require('async');
const ContractDeployer = require('./contract_deployer.js');
const utils = require('../../utils/utils.js');
//require("../utils/debug_util.js")(__filename, async);
const cloneDeep = require('clone-deep');
class DeployManager {
constructor(embark, options) {
@ -43,25 +42,37 @@ class DeployManager {
deployAll(done) {
let self = this;
self.events.request('contracts:list', (err, contracts) => {
if (err) {
return done(err);
}
self.events.request('contracts:dependencies', (err, contractDependencies) => {
self.events.request('contracts:list', (err, contracts) => {
if (err) {
return done(err);
}
self.logger.info(__("deploying contracts"));
self.events.emit("deploy:beforeAll");
self.logger.info(__("deploying contracts"));
self.events.emit("deploy:beforeAll");
const contractsPerDependencyCount = utils.groupBy(contracts, 'dependencyCount');
async.eachSeries(contractsPerDependencyCount,
function (parallelGroups, callback) {
async.each(parallelGroups, (contract, eachCb) => {
const contractDeploys = {};
contracts.forEach(contract => {
function deploy(result, callback) {
if (typeof result === 'function') {
callback = result;
}
contract._gasLimit = self.gasLimit;
self.events.request('deploy:contract', contract, (err) => {
eachCb(err);
callback(err);
});
}, callback);
},
function (err, _results) {
}
const className = contract.className;
if (!contractDependencies[className] || contractDependencies[className].length === 0) {
contractDeploys[className] = deploy;
return;
}
contractDeploys[className] = cloneDeep(contractDependencies[className]);
contractDeploys[className].push(deploy);
});
async.auto(contractDeploys, function(err, _results) {
if (err) {
self.logger.error(__("error deploying contracts"));
self.logger.error(err.message);
@ -73,8 +84,8 @@ class DeployManager {
}
self.logger.info(__("finished deploying contracts"));
done(err);
}
);
});
});
});
}
@ -102,11 +113,11 @@ class DeployManager {
},
// TODO: shouldn't be necessary
function checkCompileOnly(callback){
if(self.onlyCompile){
function checkCompileOnly(callback) {
if (self.onlyCompile) {
self.events.emit('contractsDeployed');
return done();
}
}
return callback();
},