mirror of https://github.com/embarklabs/embark.git
use async auto to deploy parallely
This commit is contained in:
parent
19f22025ad
commit
3a621f3efd
|
@ -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,6 +42,7 @@ class DeployManager {
|
|||
deployAll(done) {
|
||||
let self = this;
|
||||
|
||||
self.events.request('contracts:dependencies', (err, contractDependencies) => {
|
||||
self.events.request('contracts:list', (err, contracts) => {
|
||||
if (err) {
|
||||
return done(err);
|
||||
|
@ -51,17 +51,28 @@ class DeployManager {
|
|||
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,8 +113,8 @@ 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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue