mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] share the workers between repos
This commit is contained in:
parent
2089b04c1f
commit
1762df1747
@ -268,55 +268,56 @@ 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', 'in', ids)]
|
||||||
domain = [('repo_id', '=', repo.id)]
|
|
||||||
|
|
||||||
# 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'])])
|
||||||
Build.schedule(cr, uid, build_ids)
|
Build.schedule(cr, uid, build_ids)
|
||||||
|
|
||||||
# launch new tests
|
# launch new tests
|
||||||
|
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')])
|
||||||
|
pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')])
|
||||||
|
|
||||||
|
while testing < workers and pending > 0:
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
if not pending_ids:
|
||||||
|
pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending')], order="sequence", limit=1)
|
||||||
|
|
||||||
|
pending_build = Build.browse(cr, uid, pending_ids[0])
|
||||||
|
pending_build.schedule()
|
||||||
|
|
||||||
|
# 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')])
|
||||||
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:
|
# terminate and reap doomed build
|
||||||
|
build_ids = Build.search(cr, uid, domain + [('state', '=', 'running')])
|
||||||
# find sticky pending build if any, otherwise, last pending (by id, not by sequence) will do the job
|
# sort builds: the last build of each sticky branch then the rest
|
||||||
pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending'), ('branch_id.sticky', '=', True)], limit=1)
|
sticky = {}
|
||||||
if not pending_ids:
|
non_sticky = []
|
||||||
pending_ids = Build.search(cr, uid, domain + [('state', '=', 'pending')], order="sequence", limit=1)
|
for build in Build.browse(cr, uid, build_ids):
|
||||||
|
if build.branch_id.sticky and build.branch_id.id not in sticky:
|
||||||
pending = Build.browse(cr, uid, pending_ids[0])
|
sticky[build.branch_id.id] = build.id
|
||||||
pending.schedule()
|
else:
|
||||||
|
non_sticky.append(build.id)
|
||||||
# compute the number of testing and pending jobs again
|
build_ids = sticky.values()
|
||||||
testing = Build.search_count(cr, uid, domain + [('state', '=', 'testing')])
|
build_ids += non_sticky
|
||||||
pending = Build.search_count(cr, uid, domain + [('state', '=', 'pending')])
|
# terminate extra running builds
|
||||||
|
Build.terminate(cr, uid, build_ids[running_max:])
|
||||||
# terminate and reap doomed build
|
Build.reap(cr, uid, build_ids)
|
||||||
build_ids = Build.search(cr, uid, domain + [('state', '=', 'running')])
|
|
||||||
# sort builds: the last build of each sticky branch then the rest
|
|
||||||
sticky = {}
|
|
||||||
non_sticky = []
|
|
||||||
for build in Build.browse(cr, uid, build_ids):
|
|
||||||
if build.branch_id.sticky and build.branch_id.id not in sticky:
|
|
||||||
sticky[build.branch_id.id] = build.id
|
|
||||||
else:
|
|
||||||
non_sticky.append(build.id)
|
|
||||||
build_ids = sticky.values()
|
|
||||||
build_ids += non_sticky
|
|
||||||
# terminate extra running builds
|
|
||||||
Build.terminate(cr, uid, build_ids[repo.running:])
|
|
||||||
Build.reap(cr, uid, build_ids)
|
|
||||||
|
|
||||||
def nginx(self, cr, uid, context=None):
|
def nginx(self, cr, uid, context=None):
|
||||||
settings = {}
|
settings = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user