@@ -12,6 +12,8 @@ var fs = require('fs-extra')
1212 , cachier = require ( './cachier' )
1313 , keeper = require ( 'dirkeeper' )
1414 , JobData = require ( './jobdata' )
15+ , JobQueue = require ( './jobqueue' )
16+ , branchFromJob = require ( './utils' ) . branchFromJob
1517
1618// timeout for callbacks. Helps to kill misbehaving plugins, etc
1719function t ( time , done ) {
@@ -56,28 +58,28 @@ function Runner(emitter, config) {
5658 logger : console ,
5759 processJob : core . process ,
5860 pluginDir : path . join ( __dirname , '../node_modules' ) ,
59- dataDir : process . env . STRIDER_CLONE_DEST || dotStrider
61+ dataDir : process . env . STRIDER_CLONE_DEST || dotStrider ,
62+ concurrentJobs : parseInt ( process . env . CONCURRENT_JOBS || '1' , 10 ) || 1 ,
6063 } , config )
6164 this . emitter = emitter
6265 this . log = this . config . logger . log
63- this . queue = async . queue ( this . processJob . bind ( this ) , 1 )
66+ this . queue = new JobQueue ( this . processJob . bind ( this ) , this . config . concurrentJobs )
6467 this . io = this . config . io
6568 this . callbackMap = { }
6669 this . hooks = [ ]
6770 this . jobdata = new JobData ( this . io )
6871 this . attach ( )
6972}
7073
71- // base: the base directory where all jobs data is stored
74+ // base: the base directory where all jobs data for this project and branch is stored
7275// the job object.
7376// done(err, {base:, data:, cache:})
74- function initJobDirs ( base , job , cache , done ) {
75- var name = job . project . name
76- , dirs = {
77- base : base ,
78- data : path . join ( base , "data" , name . replace ( '/' , '-' ) + "-" + job . _id . toString ( ) ) ,
79- cache : cache
80- }
77+ function initJobDirs ( branchBase , job , cache , done ) {
78+ var dirs = {
79+ base : branchBase ,
80+ data : path . join ( branchBase , 'job-' + job . _id . toString ( ) ) ,
81+ cache : cache
82+ }
8183
8284 async . series ( [
8385 function checkData ( next ) {
@@ -179,13 +181,13 @@ Runner.prototype = {
179181 this . jobdata . add ( job )
180182 this . log ( '[runner:' + this . id + '] Queued new job. Project: ' + job . project . name + ' Job ID: ' + job . _id )
181183 this . emitter . emit ( 'browser.update' , job . project . name , 'job.status.queued' , [ job . _id , now ] )
182- this . queue . push ( { job : job , config : config } )
184+ this . queue . push ( job , config )
183185 } ,
184186
185187 cancelJob : function ( id ) {
186188 var jobdata
187189 for ( var i = 0 ; i < this . queue . tasks . length ; i ++ ) {
188- if ( this . queue . tasks [ i ] . data . job . _id . toString ( ) === id . toString ( ) ) {
190+ if ( this . queue . tasks [ i ] . job . _id . toString ( ) === id . toString ( ) ) {
189191 this . queue . tasks . splice ( i , 1 )
190192 this . log ( '[runner:' + this . id + '] Cancelled job. Job ID: ' + id )
191193 jobdata = this . jobdata . pop ( id )
@@ -280,10 +282,8 @@ Runner.prototype = {
280282 } )
281283 } ,
282284
283- processJob : function ( data , next ) {
284- var job = data . job
285- , config = data . config
286- , cache = this . getCache ( job . project )
285+ processJob : function ( job , config , next ) {
286+ var cache = this . getCache ( job . project )
287287 , now = new Date ( )
288288 , self = this
289289 , oldnext = next
@@ -292,11 +292,18 @@ Runner.prototype = {
292292 oldnext ( )
293293 }
294294 this . callbackMap [ job . _id ] = next
295- // Keep around N most recent build directories.
296- // Default is 0, ie wipe at start of each run.
295+
296+ var projectName = job . project . name . replace ( '/' , '-' )
297+ , branchName = branchFromJob ( job ) . replace ( '/' , '-' )
298+ , branchBase = path . join ( self . config . dataDir , 'data' , projectName + '-' + branchName )
299+
300+ // Keep around N most recent build directories for this branch.
301+ // The default is 0, ie wipe at start of each run.
297302 // Later, this can be configurable in the UI.
298- keeper ( { baseDir : path . join ( this . config . dataDir , "data" ) , count : 0 } , function ( err ) {
299- initJobDirs ( self . config . dataDir , job , cache . base , jobDirsReady )
303+ keeper ( { baseDir : branchBase , count : 0 } , function ( err ) {
304+ if ( err ) throw err ;
305+
306+ initJobDirs ( branchBase , job , cache . base , jobDirsReady )
300307 } )
301308
302309 var jobDirsReady = function ( err , dirs ) {
@@ -373,4 +380,3 @@ Runner.prototype = {
373380 } ;
374381 }
375382} ;
376-
0 commit comments