[IMP] runbot: auto disable host when git fetch fail

From times to times, a git repo gets corrupted, making builds fail in
chain.

With this commit, the host on which the git fetch fails will be reserved
if not more than half the hosts are reserved.
This commit is contained in:
Christophe Monniez 2020-02-25 16:23:24 +01:00
parent 6b52687ed1
commit 820adae5ac
2 changed files with 15 additions and 1 deletions

View File

@ -103,3 +103,11 @@ class RunboHost(models.Model):
def _total_workers(self):
return sum(host.get_nb_worker() for host in self)
def disable(self):
""" Reserve host if possible """
self.ensure_one()
nb_hosts = self.env['runbot.host'].search_count([])
nb_reserved = self.env['runbot.host'].search_count([('assigned_only', '=', True)])
if nb_reserved < (nb_hosts / 2):
self.assigned_only = True

View File

@ -425,7 +425,13 @@ class runbot_repo(models.Model):
# Extracted from update_git to be easily overriden in external module
self.ensure_one()
repo = self
repo._git(['fetch', '-p', 'origin', '+refs/heads/*:refs/heads/*', '+refs/pull/*/head:refs/pull/*'])
try:
repo._git(['fetch', '-p', 'origin', '+refs/heads/*:refs/heads/*', '+refs/pull/*/head:refs/pull/*'])
except subprocess.CalledProcessError as e:
message = 'Failed to fetch repo %s with return code %s. Original command was %s' % (repo.name, e.returncode, e.cmd)
_logger.exception(message)
host = self.env['runbot.host'].search([('name', '=', fqdn())])
host.disable()
def _update(self, force=True):
""" Update the physical git reposotories on FS"""