mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: add message queue
Message queue squeletton for future changes
This commit is contained in:
parent
2579a2d3fe
commit
c965c2c35a
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
|
@ -70,6 +70,7 @@
|
||||
<field name="global_result"/>
|
||||
<field name="triggered_result" groups="base.group_no_one"/>
|
||||
<field name="host"/>
|
||||
<field name="host_id"/>
|
||||
<field name="job_start" groups="base.group_no_one"/>
|
||||
<field name="job_end" groups="base.group_no_one"/>
|
||||
<field name="job_time" groups="base.group_no_one"/>
|
||||
|
@ -18,6 +18,7 @@
|
||||
<field name="nb_worker"/>
|
||||
<field name="last_exception" readonly='1'/>
|
||||
<field name="exception_count" readonly='1'/>
|
||||
<field name="host_message_ids" readonly='1'/>
|
||||
</group>
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
|
Loading…
Reference in New Issue
Block a user