mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-23 02:48:21 +00:00
Merge pull request #691 from embark-framework/features/para-deploy
More Parallel deploy
This commit is contained in:
commit
7704d1f2f5
@ -41,9 +41,6 @@ class ContractsManager {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.events.setCommandHandler("contracts:reset:dependencies", (cb) => {
|
self.events.setCommandHandler("contracts:reset:dependencies", (cb) => {
|
||||||
for (let className in self.contracts) {
|
|
||||||
self.contracts[className].dependencyCount = null;
|
|
||||||
}
|
|
||||||
self.contractDependencies = {};
|
self.contractDependencies = {};
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
@ -289,43 +286,6 @@ class ContractsManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback();
|
callback();
|
||||||
},
|
|
||||||
function setDependencyCount(callback) {
|
|
||||||
let className;
|
|
||||||
|
|
||||||
function getDependencyCount(contractName, cycleDetector) {
|
|
||||||
if (!self.contracts[contractName]) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (self.contracts[contractName].dependencyCount || self.contracts[contractName].dependencyCount === 0) {
|
|
||||||
// Already have that count
|
|
||||||
return self.contracts[contractName].dependencyCount;
|
|
||||||
}
|
|
||||||
if (!self.contractDependencies[contractName] || !self.contractDependencies[contractName].length) {
|
|
||||||
self.contracts[contractName].dependencyCount = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
let total = self.contractDependencies[contractName].length;
|
|
||||||
self.contractDependencies[contractName].some(dependencyName => {
|
|
||||||
if (cycleDetector.indexOf(dependencyName) > -1) {
|
|
||||||
// We are in a cycle because of the dependency, set both to Infinity
|
|
||||||
self.contracts[dependencyName].dependencyCount = Infinity;
|
|
||||||
total = Infinity;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
cycleDetector.push(dependencyName);
|
|
||||||
total += getDependencyCount(dependencyName, cycleDetector);
|
|
||||||
});
|
|
||||||
self.contracts[contractName].dependencyCount = total;
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
let cycleDetector;
|
|
||||||
for (className in self.contracts) {
|
|
||||||
cycleDetector = [];
|
|
||||||
getDependencyCount(className, cycleDetector);
|
|
||||||
}
|
|
||||||
callback();
|
|
||||||
}
|
}
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
let async = require('async');
|
let async = require('async');
|
||||||
|
|
||||||
const ContractDeployer = require('./contract_deployer.js');
|
const ContractDeployer = require('./contract_deployer.js');
|
||||||
const utils = require('../../utils/utils.js');
|
const cloneDeep = require('clone-deep');
|
||||||
//require("../utils/debug_util.js")(__filename, async);
|
|
||||||
|
|
||||||
class DeployManager {
|
class DeployManager {
|
||||||
constructor(embark, options) {
|
constructor(embark, options) {
|
||||||
@ -43,25 +42,37 @@ class DeployManager {
|
|||||||
deployAll(done) {
|
deployAll(done) {
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
self.events.request('contracts:list', (err, contracts) => {
|
self.events.request('contracts:dependencies', (err, contractDependencies) => {
|
||||||
if (err) {
|
self.events.request('contracts:list', (err, contracts) => {
|
||||||
return done(err);
|
if (err) {
|
||||||
}
|
return done(err);
|
||||||
|
}
|
||||||
|
|
||||||
self.logger.info(__("deploying contracts"));
|
self.logger.info(__("deploying contracts"));
|
||||||
self.events.emit("deploy:beforeAll");
|
self.events.emit("deploy:beforeAll");
|
||||||
|
|
||||||
const contractsPerDependencyCount = utils.groupBy(contracts, 'dependencyCount');
|
const contractDeploys = {};
|
||||||
async.eachSeries(contractsPerDependencyCount,
|
contracts.forEach(contract => {
|
||||||
function (parallelGroups, callback) {
|
function deploy(result, callback) {
|
||||||
async.each(parallelGroups, (contract, eachCb) => {
|
if (typeof result === 'function') {
|
||||||
|
callback = result;
|
||||||
|
}
|
||||||
contract._gasLimit = self.gasLimit;
|
contract._gasLimit = self.gasLimit;
|
||||||
self.events.request('deploy:contract', contract, (err) => {
|
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) {
|
if (err) {
|
||||||
self.logger.error(__("error deploying contracts"));
|
self.logger.error(__("error deploying contracts"));
|
||||||
self.logger.error(err.message);
|
self.logger.error(err.message);
|
||||||
@ -73,8 +84,8 @@ class DeployManager {
|
|||||||
}
|
}
|
||||||
self.logger.info(__("finished deploying contracts"));
|
self.logger.info(__("finished deploying contracts"));
|
||||||
done(err);
|
done(err);
|
||||||
}
|
});
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,11 +113,11 @@ class DeployManager {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// TODO: shouldn't be necessary
|
// TODO: shouldn't be necessary
|
||||||
function checkCompileOnly(callback){
|
function checkCompileOnly(callback) {
|
||||||
if(self.onlyCompile){
|
if (self.onlyCompile) {
|
||||||
self.events.emit('contractsDeployed');
|
self.events.emit('contractsDeployed');
|
||||||
return done();
|
return done();
|
||||||
}
|
}
|
||||||
return callback();
|
return callback();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user