Skip to content

Commit

Permalink
Merge branch 'develop' into feature_coalescing-support
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehuntsman committed Mar 14, 2016
2 parents c8aeffe + a041517 commit c01d65c
Show file tree
Hide file tree
Showing 11 changed files with 1,074 additions and 224 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git*
*.md
.jsh*
.travis*
.totem*
totem*
AUTHORS
LICENSE
*.apib
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: node_js
node_js:
- '0.10'
before_install:
npm install -g npm
sudo: false
script: './node_modules/.bin/grunt travis'
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM totem/nodejs-base:0.10.38-trusty-b2
FROM totem/nodejs-base:0.10.42

ENV DEBIAN_FRONTEND noninteractive

Expand Down
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-mocha-cov');
grunt.loadNpmTasks('grunt-contrib-jshint');

grunt.registerTask('test', ['jshint', 'mochacov:unit', 'mochacov:coverage']);
grunt.registerTask('travis', ['jshint', 'mochacov:unit', 'mochacov:coverage', 'mochacov:coveralls']);
grunt.registerTask('test', ['jshint', 'mochacov:unit']);
grunt.registerTask('travis', ['jshint', 'mochacov:unit', 'mochacov:coveralls']);
grunt.registerTask('default', 'test');

};
1 change: 1 addition & 0 deletions config/config-docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"retryWait": 20000
}
},
"concurrentJobs" : 2,
"colaescingPeriod": 30000,
"swf":{
"region": "us-west-1",
Expand Down
1 change: 1 addition & 0 deletions config/config-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"timeout": "1800000"
}
},
"concurrentJobs" : 2,
"colaescingPeriod": 30000,
"swf":{
"region": "us-west-1",
Expand Down
1 change: 1 addition & 0 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"retryWait": 20000
}
},
"concurrentJobs" : 2,
"colaescingPeriod": 30000,
"swf":{
"region": "us-west-1",
Expand Down
48 changes: 34 additions & 14 deletions lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var DEFAULT_CONFIG = {
timeout: 1800000 // 30 minutes
}
},
concurrentJobs: 1,
coalescingPeriod: 30000,
hook: {
secret: process.env.HOOK_SECRET || 'changeit',
Expand All @@ -87,6 +88,9 @@ function Factory(config) {

// Merge in custom config with defaults
_.defaults(config, DEFAULT_CONFIG);

// Store reference to current object
var _this = this;

// Save our config
this.config = config;
Expand All @@ -97,6 +101,29 @@ function Factory(config) {
// Datastore for jobs
this.jobs = new Datastore();

// Initializes an empty job queue
this.jobQueue = async.queue(function(job, callback) {

// Start building an image when a job is taken from the queue
job.start(function (err) {
callback(err); // Job is considered finished

var isSuccessful = (err ? false : true);
var image = _this.getImage(job);

//Notify build was successful / failed.
var notifyCtx = _.extend({}, job.context, {
baseUrl: _this.config.baseUrl,
env: _this.config.env,
id: job.id
});
_.forEach(_this.notifiers, function(notifier) {
notifier.notify(isSuccessful, notifyCtx, image);
});

});
}, this.config.concurrentJobs); // Limit the number of concurrent jobs

// Notification for job
this.notifiers = [
new PostHookNotifier(config.hook),
Expand All @@ -105,7 +132,6 @@ function Factory(config) {

// Initialize the API
this.initApi();

}

// Ensure we can emit events
Expand Down Expand Up @@ -334,19 +360,13 @@ Factory.prototype.newJob = function newJob(context) {
// Store the Job in the datastore
_this.jobs.put(job.id, job);

// Start building the image
job.start(function (err) {
var isSuccessful = (err ? false : true);
var image = _this.getImage(job);
//Notify build was successful / failed.
var notifyCtx = _.extend({}, context, {
baseUrl: _this.config.baseUrl,
env: _this.config.env,
id: job.id
});
_.forEach(_this.notifiers, function(notifier) {
notifier.notify(isSuccessful, notifyCtx, image);
});
// Add the Job to the job queue
_this.jobQueue.push(job, function(err) {
if(err) {
winston.log('debug', 'Finished job ' + job.id + ' with errors.\n' + err.message);
} else {
winston.log('debug', 'Finished job ' + job.id);
}
});

return job;
Expand Down
4 changes: 3 additions & 1 deletion lib/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var os = require('os'),
_ = require('lodash'),
formatter = require('formatter'),
constants = require('./constants'),
helpers = require('./util');
helpers = require('./util'),
winston = require('winston');


// Export the JobRunner class
Expand Down Expand Up @@ -135,6 +136,7 @@ Job.prototype.start = function start(cb) {

_this.emit(this.status);

winston.log('debug', 'Started building job ' + _this.id);
// Start building the image
this._executeJob(function (err) {

Expand Down

0 comments on commit c01d65c

Please sign in to comment.