[IMP] runbot: select for update in ask_kill

When a build has a lot of children, _ask_kill can fail due to concurrent_update.
This solution locks all build before reading/updating builds.
This commit is contained in:
Xavier-Do 2020-01-17 12:18:31 +01:00 committed by Christophe Monniez
parent 534bb728ce
commit 7058868c0f

View File

@ -868,8 +868,9 @@ class runbot_build(models.Model):
build._github_status()
self.invalidate_cache()
def _ask_kill(self):
# todo xdo, should we kill or skip children builds? it looks like yes, but we need to be carefull if subbuild can be duplicates
def _ask_kill(self, lock=True):
if lock:
self.env.cr.execute("""SELECT id FROM runbot_build WHERE parent_path like %s FOR UPDATE""", ['%s%%' % self.parent_path])
self.ensure_one()
user = request.env.user if request else self.env.user
uid = user.id
@ -888,7 +889,7 @@ class runbot_build(models.Model):
build._log('_ask_kill', 'Killing build %s, requested by %s (user #%s)' % (build.dest, user.name, uid))
for child in build.children_ids: # should we filter build that are target of a duplicate_id?
if not child.duplicate_id:
child._ask_kill()
child._ask_kill(lock=False)
def _wake_up(self):
build = self.real_build