move avg build calculation from lib distributor - fix tests

This commit is contained in:
oleg 2015-07-28 23:40:26 +03:00
parent 0df4b2771f
commit 2f0c87ceac
2 changed files with 17 additions and 7 deletions

View File

@ -3,6 +3,9 @@
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
Distributor = require('./lib/distributor').Distributor,
getAvgProjectBuildDuration = (
require('./lib/project').getAvgProjectBuildDuration
),
db = require('./db'),
path = require('path'),
fs = require('fs'),
@ -16,6 +19,15 @@ exports.init = function(app, callback) {
saveBuild: function(build, callback) {
Steppy(
function() {
if (!_(build.project).has('avgBuildDuration')) {
getAvgProjectBuildDuration(build.project.name, this.slot());
} else {
this.pass(build.project.avgBuildDuration);
}
},
function(err, avgBuildDuration) {
build.project.avgBuildDuration = avgBuildDuration;
db.builds.put(build, this.slot());
},
function() {

View File

@ -3,7 +3,6 @@
var Steppy = require('twostep').Steppy,
_ = require('underscore'),
Node = require('./node').Node,
getAvgProjectBuildDuration = require('./project').getAvgProjectBuildDuration,
EventEmitter = require('events').EventEmitter,
inherits = require('util').inherits,
notifier = require('./notifier'),
@ -220,17 +219,18 @@ Distributor.prototype.run = function(params, callback) {
};
Steppy(
function() {
project = _(self.projects).findWhere({name: params.projectName});
project = _(self.projects).chain()
.findWhere({name: params.projectName})
.clone()
.value();
if (params.withScmChangesOnly) {
self.nodes[0].hasScmChanges(project, this.slot());
} else {
this.pass(null);
}
getAvgProjectBuildDuration(params.projectName, this.slot());
},
function(err, hasScmChanges, avgProjectBuildDuration) {
function(err, hasScmChanges) {
if (params.withScmChangesOnly && !hasScmChanges) {
logger.log(
'Building of "%s" skipped coz no scm changes',
@ -239,8 +239,6 @@ Distributor.prototype.run = function(params, callback) {
return callback();
}
project.avgBuildDuration = avgProjectBuildDuration;
self._updateBuild({}, {
project: project,
initiator: params.initiator,