[IMP] share the workers between repos

This commit is contained in:
Gery Debongnie 2014-07-15 11:33:38 +02:00
parent 2089b04c1f
commit 1762df1747

View File

@ -268,17 +268,18 @@ class runbot_repo(osv.osv):
# skip old builds (if their sequence number is too low, they will not ever be built) # skip old builds (if their sequence number is too low, they will not ever be built)
skippable_domain = [('repo_id', '=', repo.id), ('state', '=', 'pending')] skippable_domain = [('repo_id', '=', repo.id), ('state', '=', 'pending')]
to_be_skipped_ids = Build.search(cr, uid, skippable_domain, order='sequence desc', offset=repo.running) icp = self.pool['ir.config_parameter']
running_max = int(icp.get_param(cr, uid, 'runbot.running_max', default=75))
to_be_skipped_ids = Build.search(cr, uid, skippable_domain, order='sequence desc', offset=running_max)
Build.write(cr, uid, to_be_skipped_ids, {'state': 'done', 'result': 'skipped'}) Build.write(cr, uid, to_be_skipped_ids, {'state': 'done', 'result': 'skipped'})
def scheduler(self, cr, uid, ids=None, context=None): def scheduler(self, cr, uid, ids=None, context=None):
icp = self.pool['ir.config_parameter'] icp = self.pool['ir.config_parameter']
workers = icp.get_param(cr, uid, 'runbot.workers', default=6) workers = int(icp.get_param(cr, uid, 'runbot.workers', default=6))
running_max = icp.get_param(cr, uid, 'runbot.running_max', default=75) running_max = int(icp.get_param(cr, uid, 'runbot.running_max', default=75))
for repo in self.browse(cr, uid, ids, context=context):
Build = self.pool['runbot.build'] Build = self.pool['runbot.build']
domain = [('repo_id', '=', repo.id)] domain = [('repo_id', 'in', ids)]
# schedule jobs (transitions testing -> running, kill jobs, ...) # schedule jobs (transitions testing -> running, kill jobs, ...)
build_ids = Build.search(cr, uid, domain + [('state', 'in', ['testing', 'running'])]) build_ids = Build.search(cr, uid, domain + [('state', 'in', ['testing', 'running'])])
@ -288,15 +289,15 @@ class runbot_repo(osv.osv):
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')]) testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')])
pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')]) pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')])
while testing < repo.testing and pending > 0: while testing < workers and pending > 0:
# find sticky pending build if any, otherwise, last pending (by id, not by sequence) will do the job # find sticky pending build if any, otherwise, last pending (by id, not by sequence) will do the job
pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending'), ('branch_id.sticky', '=', True)], limit=1) pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending'), ('branch_id.sticky', '=', True)], limit=1)
if not pending_ids: if not pending_ids:
pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending')], order="sequence", limit=1) pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending')], order="sequence", limit=1)
pending = Build.browse(cr, uid, pending_ids[0]) pending_build = Build.browse(cr, uid, pending_ids[0])
pending.schedule() pending_build.schedule()
# compute the number of testing and pending jobs again # compute the number of testing and pending jobs again
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')]) testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')])
@ -315,7 +316,7 @@ class runbot_repo(osv.osv):
build_ids = sticky.values() build_ids = sticky.values()
build_ids += non_sticky build_ids += non_sticky
# terminate extra running builds # terminate extra running builds
Build.terminate(cr, uid, build_ids[repo.running:]) Build.terminate(cr, uid, build_ids[running_max:])
Build.reap(cr, uid, build_ids) Build.reap(cr, uid, build_ids)
def nginx(self, cr, uid, context=None): def nginx(self, cr, uid, context=None):