mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: host improvement
This commit is contained in:
parent
d2f9330043
commit
d164d9a745
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import getpass
|
||||
import time
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
@ -10,8 +11,6 @@ from ..container import docker_build
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
forced_host_name = None
|
||||
|
||||
|
||||
class Host(models.Model):
|
||||
_name = 'runbot.host'
|
||||
@ -37,6 +36,7 @@ class Host(models.Model):
|
||||
exception_count = fields.Integer('Exception count')
|
||||
psql_conn_count = fields.Integer('SQL connections count', default=0)
|
||||
host_message_ids = fields.One2many('runbot.host.message', 'host_id')
|
||||
build_ids = fields.One2many('runbot.build', compute='_compute_build_ids')
|
||||
|
||||
def _compute_nb(self):
|
||||
groups = self.env['runbot.build'].read_group(
|
||||
@ -52,6 +52,10 @@ class Host(models.Model):
|
||||
host.nb_testing = count_by_host_state[host.name].get('testing', 0)
|
||||
host.nb_running = count_by_host_state[host.name].get('running', 0)
|
||||
|
||||
def _compute_build_ids(self):
|
||||
for host in self:
|
||||
host.build_ids = self.env['runbot.build'].search([('host', '=', host.name), ('local_state', '!=', 'done')])
|
||||
|
||||
@api.model_create_single
|
||||
def create(self, values):
|
||||
if 'disp_name' not in values:
|
||||
@ -113,9 +117,11 @@ class Host(models.Model):
|
||||
self.clear_caches() # needed to ensure that content is updated on all hosts
|
||||
for dockerfile in self.env['runbot.dockerfile'].search([('to_build', '=', True)]):
|
||||
self._docker_build_dockerfile(dockerfile, static_path)
|
||||
_logger.info('Done...')
|
||||
|
||||
def _docker_build_dockerfile(self, dockerfile, workdir):
|
||||
_logger.info('Building %s, %s', dockerfile.name, hash(str(dockerfile.dockerfile)))
|
||||
start = time.time()
|
||||
# _logger.info('Building %s, %s', dockerfile.name, hash(str(dockerfile.dockerfile)))
|
||||
docker_build_path = os.path.join(workdir, 'docker', dockerfile.image_tag)
|
||||
os.makedirs(docker_build_path, exist_ok=True)
|
||||
|
||||
@ -137,7 +143,11 @@ class Host(models.Model):
|
||||
if not docker_build_success:
|
||||
dockerfile.to_build = False
|
||||
dockerfile.message_post(body=f'Build failure:\n{msg}')
|
||||
self.env['runbot.runbot'].warning(f'Dockerfile build "{dockerfile.image_tag}" failed on host {self.name}')
|
||||
# self.env['runbot.runbot'].warning(f'Dockerfile build "{dockerfile.image_tag}" failed on host {self.name}')
|
||||
else:
|
||||
duration = time.time() - start
|
||||
if duration > 1:
|
||||
_logger.info('Dockerfile %s finished build in %s', dockerfile.image_tag, duration)
|
||||
|
||||
def _get_work_path(self):
|
||||
return os.path.abspath(os.path.join(os.path.dirname(__file__), '../static'))
|
||||
|
Loading…
Reference in New Issue
Block a user