diff --git a/runbot/models/build.py b/runbot/models/build.py index a2355ffa..3a792522 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -163,7 +163,8 @@ class BuildResult(models.Model): requested_action = fields.Selection([('wake_up', 'To wake up'), ('deathrow', 'To kill')], string='Action requested', index=True) # web infos - host = fields.Char('Host') + host = fields.Char('Host name') + host_id = fields.Many2one('runbot.host', string="Host", compute='_compute_host_id') keep_host = fields.Boolean('Keep host on rebuild and for children') port = fields.Integer('Port') @@ -233,6 +234,12 @@ class BuildResult(models.Model): for build in self: build.display_name = build.description or build.config_id.name + @api.depends('host') + def _compute_host_id(self): + get_host = self.env['runbot.host']._get_host + for record in self: + record.host_id = get_host(record.host) + @api.depends('params_id.config_id') def _compute_log_list(self): # storing this field because it will be access trhoug repo viewn and keep track of the list at create for build in self: diff --git a/runbot/models/host.py b/runbot/models/host.py index cd84e6ea..ff92d0dd 100644 --- a/runbot/models/host.py +++ b/runbot/models/host.py @@ -4,7 +4,7 @@ import getpass from collections import defaultdict from odoo import models, fields, api -from odoo.tools import config +from odoo.tools import config, ormcache from ..common import fqdn, local_pgadmin_cursor, os, list_local_dbs, local_pg_cursor from ..container import docker_build @@ -36,6 +36,7 @@ class Host(models.Model): last_exception = fields.Char('Last exception') 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') def _compute_nb(self): groups = self.env['runbot.build'].read_group( @@ -140,11 +141,18 @@ class Host(models.Model): def _get_work_path(self): return os.path.abspath(os.path.join(os.path.dirname(__file__), '../static')) + + @ormcache() + def _host_list(self): + return {host.name: host.id for host in self.search([])} + + def _get_host(self, name): + return self.browse(self._host_list().get(name)) or self.with_context(active_test=False).search([('name', '=', name)]) @api.model def _get_current(self): name = self._get_current_name() - return self.search([('name', '=', name)]) or self.create({'name': name}) + return self._get_host(name) or self.create({'name': name}) @api.model def _get_current_name(self): @@ -244,3 +252,26 @@ class Host(models.Model): logs_db_name = self.env['ir.config_parameter'].get_param('runbot.logdb_name') with local_pg_cursor(logs_db_name) as local_cr: local_cr.execute("DELETE FROM ir_logging WHERE id in %s", [tuple(local_log_ids)]) + + def _process_messages(self): + self.host_message_ids._process() + + +class MessageQueue(models.Model): + _name = 'runbot.host.message' + _description = "Message queue" + _order = 'id' + _log_access = False + + create_date = fields.Datetime('Create date', default=fields.Datetime.now) + host_id = fields.Many2one('runbot.host', required=True, ondelete='cascade') + build_id = fields.Many2one('runbot.build') + message = fields.Char('Message') + + def _process(self): + records = self + # todo consume messages here + if records: + for record in records: + self.env['runbot.runbot'].warning(f'Host {record.host_id.name} got an unexpected message {record.message}') + self.unlink() diff --git a/runbot/models/runbot.py b/runbot/models/runbot.py index 679dfc1f..1b967f34 100644 --- a/runbot/models/runbot.py +++ b/runbot/models/runbot.py @@ -45,6 +45,8 @@ class Runbot(models.AbstractModel): self._commit() host.process_logs() self._commit() + host._process_messages() + self._commit() for build in self._get_builds_to_schedule(host): build = build.browse(build.id) # remove preftech ids, manage build one by one build._schedule() diff --git a/runbot/security/ir.model.access.csv b/runbot/security/ir.model.access.csv index 5a16a039..1b0273ae 100644 --- a/runbot/security/ir.model.access.csv +++ b/runbot/security/ir.model.access.csv @@ -129,3 +129,5 @@ access_runbot_commit_export_admin,runbot_commit_export_admin,runbot.model_runbot access_runbot_trigger_custom_wizard,access_runbot_trigger_custom_wizard,model_runbot_trigger_custom_wizard,runbot.group_runbot_admin,1,1,1,1 access_runbot_build_stat_regex_wizard,access_runbot_build_stat_regex_wizard,model_runbot_build_stat_regex_wizard,runbot.group_runbot_admin,1,1,1,1 + +access_runbot_host_message,access_runbot_host_message,runbot.model_runbot_host_message,runbot.group_runbot_admin,1,0,0,0 diff --git a/runbot/views/build_views.xml b/runbot/views/build_views.xml index 524999bb..41fe358c 100644 --- a/runbot/views/build_views.xml +++ b/runbot/views/build_views.xml @@ -70,6 +70,7 @@ + diff --git a/runbot/views/host_views.xml b/runbot/views/host_views.xml index 767dc3a2..577fc96c 100644 --- a/runbot/views/host_views.xml +++ b/runbot/views/host_views.xml @@ -18,6 +18,7 @@ +