mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 19:09:16 +00:00
move calculating of average build duration for the project to builds collenction
This commit is contained in:
parent
4da569083b
commit
3858c3a0d0
@ -17,7 +17,9 @@ exports.init = function(app, callback) {
|
||||
if (_(build.project).has('avgBuildDuration')) {
|
||||
this.pass(build.project.avgBuildDuration);
|
||||
} else {
|
||||
app.projects.getAvgBuildDuration(build.project.name, this.slot());
|
||||
app.builds.getProjectAvgBuildDuration({
|
||||
projectName: build.project.name
|
||||
}, this.slot());
|
||||
}
|
||||
},
|
||||
function(err, avgBuildDuration) {
|
||||
|
@ -1,14 +1,3 @@
|
||||
- [ProjectsCollection()](#projectscollection)
|
||||
- [ProjectsCollection.validateConfig():Function)](#projectscollectionvalidateconfigconfigobjectcallbackerrconfigfunction)
|
||||
- [ProjectsCollection.load()]:Function)](#projectscollectionloadnamestringcallbackerrfunction)
|
||||
- [ProjectsCollection.loadAll()]:Function)](#projectscollectionloadallcallbackerrfunction)
|
||||
- [ProjectsCollection.unload()]:Function)](#projectscollectionunloadnamestringcallbackerrfunction)
|
||||
- [ProjectsCollection.get()](#projectscollectiongetnamestring)
|
||||
- [ProjectsCollection.getAll()](#projectscollectiongetall)
|
||||
- [ProjectsCollection.filter()](#projectscollectionfilterpredicatefunction)
|
||||
- [ProjectsCollection.getAvgBuildDuration():Function)](#projectscollectiongetavgbuilddurationnamestringcallbackerrdurationfunction)
|
||||
- [ProjectsCollection.remove()]:Function)](#projectscollectionremovenamestringcallbackerrfunction)
|
||||
- [ProjectsCollection.rename()]:Function)](#projectscollectionrenamenamestringcallbackerrfunction)
|
||||
|
||||
## ProjectsCollection()
|
||||
|
||||
@ -20,7 +9,7 @@
|
||||
|
||||
## ProjectsCollection.validateConfig(config:Object, callback(err,config):Function)
|
||||
|
||||
Validate and return given config
|
||||
Validate and return given config.
|
||||
|
||||
## ProjectsCollection.load(name:String, [callback(err)]:Function)
|
||||
|
||||
@ -55,10 +44,6 @@
|
||||
Returns array of config objects or empty array if there is no matched
|
||||
project.
|
||||
|
||||
## ProjectsCollection.getAvgBuildDuration(name:String, callback(err,duration):Function)
|
||||
|
||||
Calculates average build duration (in ms) for the given project
|
||||
|
||||
## ProjectsCollection.remove(name:String, [callback(err)]:Function)
|
||||
|
||||
Remove project by name.
|
||||
|
34
lib/build.js
34
lib/build.js
@ -98,3 +98,37 @@ BuildsCollection.prototype.getLogLinesTail = function(params, callback) {
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate average build duration (in ms) for the given project.
|
||||
*
|
||||
* @param {String} params.projectName
|
||||
* @param {Number} [params.buildsCount]
|
||||
* @param {Function} callback(err,duration)
|
||||
*/
|
||||
BuildsCollection.prototype.getProjectAvgBuildDuration = function(params, callback) {
|
||||
params.buildsCount = params.buildsCount || 10;
|
||||
var self = this;
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
// get last done builds to calc avg build time
|
||||
self.db.builds.find({
|
||||
start: {
|
||||
projectName: params.projectName,
|
||||
status: 'done',
|
||||
descCreateDate: ''
|
||||
},
|
||||
limit: params.buildsCount
|
||||
}, this.slot());
|
||||
},
|
||||
function(err, doneBuilds) {
|
||||
var durationsSum = _(doneBuilds).reduce(function(memo, build) {
|
||||
return memo + (build.endDate - build.startDate);
|
||||
}, 0);
|
||||
|
||||
this.pass(Math.round(durationsSum / doneBuilds.length));
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
@ -240,38 +240,6 @@ ProjectsCollection.prototype.filter = function(predicate) {
|
||||
return _(this.configs).filter(predicate);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate average build duration (in ms) for the given project.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} callback(err,duration)
|
||||
*/
|
||||
ProjectsCollection.prototype.getAvgBuildDuration = function(name, callback) {
|
||||
var self = this;
|
||||
|
||||
Steppy(
|
||||
function() {
|
||||
// get last done builds to calc avg build time
|
||||
self.db.builds.find({
|
||||
start: {
|
||||
projectName: name,
|
||||
status: 'done',
|
||||
descCreateDate: ''
|
||||
},
|
||||
limit: 10
|
||||
}, this.slot());
|
||||
},
|
||||
function(err, doneBuilds) {
|
||||
var durationsSum = _(doneBuilds).reduce(function(memo, build) {
|
||||
return memo + (build.endDate - build.startDate);
|
||||
}, 0);
|
||||
|
||||
this.pass(Math.round(durationsSum / doneBuilds.length));
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove project by name.
|
||||
* Calls `unload`, removes project from disk and db.
|
||||
|
@ -10,7 +10,7 @@
|
||||
"test": "npm run makeTestRepos && mocha --bail --reporter=spec --timeout 10000",
|
||||
"dev": "gulp",
|
||||
"sync": "npm install && npm prune && bower install && bower prune",
|
||||
"docProjectsCollection": "dox --api --skipSingleStar < lib/project.js > docs/developing-plugins/projects-collection.md",
|
||||
"docProjectsCollection": "dox --api --skipSingleStar < lib/project.js | sed '/^ - \\[ProjectsCollection/ d' > docs/developing-plugins/projects-collection.md",
|
||||
"buildJs": "r.js -o static/js/requirejs/buid.js",
|
||||
"buildClean": "rm static/index.html",
|
||||
"buildHtml": "jade views/index.jade --obj '{\"env\": \"production\"}' -o static/",
|
||||
|
@ -34,7 +34,9 @@ module.exports = function(app) {
|
||||
function() {
|
||||
project = app.projects.get(name);
|
||||
|
||||
app.projects.getAvgBuildDuration(project.name, this.slot());
|
||||
app.builds.getProjectAvgBuildDuration({
|
||||
projectName: project.name
|
||||
}, this.slot());
|
||||
|
||||
// get last done build
|
||||
app.builds.find({
|
||||
|
Loading…
Reference in New Issue
Block a user