From eb9eeb670a9cdca5d742fc7397bf87f310cfc178 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 1 Oct 2019 07:54:24 +0200 Subject: [PATCH] [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. --- runbot_merge/models/pull_requests.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/runbot_merge/models/pull_requests.py b/runbot_merge/models/pull_requests.py index 64b54d99..808733a7 100644 --- a/runbot_merge/models/pull_requests.py +++ b/runbot_merge/models/pull_requests.py @@ -1263,18 +1263,20 @@ class Commit(models.Model): PRs = self.env['runbot_merge.pull_requests'] # chances are low that we'll have more than one commit for c in self.search([('to_check', '=', True)]): - c.to_check = False - st = json.loads(c.statuses) - pr = PRs.search([('head', '=', c.sha)]) - if pr: - pr._validate(st) - # heads is a json-encoded mapping of reponame:head, so chances - # are if a sha matches a heads it's matching one of the shas - stagings = Stagings.search([('heads', 'ilike', c.sha)]) - if stagings: - stagings._validate() - - self.env.cr.commit() + try: + with self.env.cr: + c.to_check = False + st = json.loads(c.statuses) + pr = PRs.search([('head', '=', c.sha)]) + if pr: + pr._validate(st) + # heads is a json-encoded mapping of reponame:head, so chances + # are if a sha matches a heads it's matching one of the shas + stagings = Stagings.search([('heads', 'ilike', c.sha)]) + if stagings: + stagings._validate() + except Exception: + _logger.exception("Failed to apply commit %s (%s)", c, c.sha) _sql_constraints = [ ('unique_sha', 'unique (sha)', 'no duplicated commit'),