[IMP] runbot: add message queue

Message queue squeletton for future changes
This commit is contained in:
Xavier-Do 2023-03-17 11:15:18 +01:00 committed by Christophe Monniez
parent 2579a2d3fe
commit c965c2c35a
6 changed files with 47 additions and 3 deletions

View File

@ -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) requested_action = fields.Selection([('wake_up', 'To wake up'), ('deathrow', 'To kill')], string='Action requested', index=True)
# web infos # 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') keep_host = fields.Boolean('Keep host on rebuild and for children')
port = fields.Integer('Port') port = fields.Integer('Port')
@ -233,6 +234,12 @@ class BuildResult(models.Model):
for build in self: for build in self:
build.display_name = build.description or build.config_id.name 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') @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 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: for build in self:

View File

@ -4,7 +4,7 @@ import getpass
from collections import defaultdict from collections import defaultdict
from odoo import models, fields, api 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 ..common import fqdn, local_pgadmin_cursor, os, list_local_dbs, local_pg_cursor
from ..container import docker_build from ..container import docker_build
@ -36,6 +36,7 @@ class Host(models.Model):
last_exception = fields.Char('Last exception') last_exception = fields.Char('Last exception')
exception_count = fields.Integer('Exception count') exception_count = fields.Integer('Exception count')
psql_conn_count = fields.Integer('SQL connections count', default=0) psql_conn_count = fields.Integer('SQL connections count', default=0)
host_message_ids = fields.One2many('runbot.host.message', 'host_id')
def _compute_nb(self): def _compute_nb(self):
groups = self.env['runbot.build'].read_group( groups = self.env['runbot.build'].read_group(
@ -140,11 +141,18 @@ class Host(models.Model):
def _get_work_path(self): def _get_work_path(self):
return os.path.abspath(os.path.join(os.path.dirname(__file__), '../static')) 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 @api.model
def _get_current(self): def _get_current(self):
name = self._get_current_name() 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 @api.model
def _get_current_name(self): 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') logs_db_name = self.env['ir.config_parameter'].get_param('runbot.logdb_name')
with local_pg_cursor(logs_db_name) as local_cr: 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)]) 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()

View File

@ -45,6 +45,8 @@ class Runbot(models.AbstractModel):
self._commit() self._commit()
host.process_logs() host.process_logs()
self._commit() self._commit()
host._process_messages()
self._commit()
for build in self._get_builds_to_schedule(host): for build in self._get_builds_to_schedule(host):
build = build.browse(build.id) # remove preftech ids, manage build one by one build = build.browse(build.id) # remove preftech ids, manage build one by one
build._schedule() build._schedule()

View File

@ -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_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_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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
129
130
131
132
133

View File

@ -70,6 +70,7 @@
<field name="global_result"/> <field name="global_result"/>
<field name="triggered_result" groups="base.group_no_one"/> <field name="triggered_result" groups="base.group_no_one"/>
<field name="host"/> <field name="host"/>
<field name="host_id"/>
<field name="job_start" groups="base.group_no_one"/> <field name="job_start" groups="base.group_no_one"/>
<field name="job_end" groups="base.group_no_one"/> <field name="job_end" groups="base.group_no_one"/>
<field name="job_time" groups="base.group_no_one"/> <field name="job_time" groups="base.group_no_one"/>

View File

@ -18,6 +18,7 @@
<field name="nb_worker"/> <field name="nb_worker"/>
<field name="last_exception" readonly='1'/> <field name="last_exception" readonly='1'/>
<field name="exception_count" readonly='1'/> <field name="exception_count" readonly='1'/>
<field name="host_message_ids" readonly='1'/>
</group> </group>
</sheet> </sheet>
<div class="oe_chatter"> <div class="oe_chatter">