[IMP] forwardport: avoid locking cron when a _validate blows up

If a _validate call blows up, the entire Commit._notify cron gets
stuck, which is an issue because not only does it stop creating
forward ports, it also stops "progressing" stagings.
This commit is contained in:
Xavier Morel 2019-10-01 07:54:24 +02:00
parent 7659293a2b
commit eb9eeb670a

View File

@ -1263,18 +1263,20 @@ class Commit(models.Model):
PRs = self.env['runbot_merge.pull_requests'] PRs = self.env['runbot_merge.pull_requests']
# chances are low that we'll have more than one commit # chances are low that we'll have more than one commit
for c in self.search([('to_check', '=', True)]): for c in self.search([('to_check', '=', True)]):
c.to_check = False try:
st = json.loads(c.statuses) with self.env.cr:
pr = PRs.search([('head', '=', c.sha)]) c.to_check = False
if pr: st = json.loads(c.statuses)
pr._validate(st) pr = PRs.search([('head', '=', c.sha)])
# heads is a json-encoded mapping of reponame:head, so chances if pr:
# are if a sha matches a heads it's matching one of the shas pr._validate(st)
stagings = Stagings.search([('heads', 'ilike', c.sha)]) # heads is a json-encoded mapping of reponame:head, so chances
if stagings: # are if a sha matches a heads it's matching one of the shas
stagings._validate() stagings = Stagings.search([('heads', 'ilike', c.sha)])
if stagings:
self.env.cr.commit() stagings._validate()
except Exception:
_logger.exception("Failed to apply commit %s (%s)", c, c.sha)
_sql_constraints = [ _sql_constraints = [
('unique_sha', 'unique (sha)', 'no duplicated commit'), ('unique_sha', 'unique (sha)', 'no duplicated commit'),