mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[FIX] runbot: fix invalid db_name log local
If the db_name does not stat with a build ind (or at least an int) the query will fail because of 'local_pg_cursor' Since a database can be create with an invalid name from the db manager but still log in the runbot_logs, we need to manage all format. Also add a limit to catchup if the db is full of logs, to avoid a Memory error.
This commit is contained in:
parent
a6ce3dceb0
commit
0d6ec3e038
@ -179,27 +179,27 @@ class Host(models.Model):
|
|||||||
def _fetch_local_logs(self, build_ids=None):
|
def _fetch_local_logs(self, build_ids=None):
|
||||||
""" fetch build logs from local database """
|
""" fetch build logs from local database """
|
||||||
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')
|
||||||
try:
|
with local_pg_cursor(logs_db_name) as local_cr:
|
||||||
with local_pg_cursor(logs_db_name) as local_cr:
|
res = []
|
||||||
res = []
|
where_clause = "WHERE split_part(dbname, '-', 1) IN %s" if build_ids else ''
|
||||||
where_clause = 'WHERE build_id IN (%s)' if build_ids else ''
|
query = f"""
|
||||||
query = f"""
|
SELECT *
|
||||||
SELECT *
|
FROM (
|
||||||
FROM (
|
SELECT id, create_date, name, level, dbname, func, path, line, type, message, split_part(dbname, '-', 1) as build_id
|
||||||
SELECT id, create_date, name, level, dbname, func, path, line, type, message, split_part(dbname, '-', 1)::integer as build_id
|
FROM ir_logging
|
||||||
FROM ir_logging
|
)
|
||||||
)
|
AS ir_logs
|
||||||
AS ir_logs
|
{where_clause}
|
||||||
{where_clause}
|
ORDER BY id
|
||||||
ORDER BY id
|
LIMIT 10000
|
||||||
"""
|
"""
|
||||||
local_cr.execute(query, build_ids)
|
if build_ids:
|
||||||
col_names = [col.name for col in local_cr.description]
|
build_ids = [tuple(str(build) for build in build_ids)]
|
||||||
for row in local_cr.fetchall():
|
local_cr.execute(query, build_ids)
|
||||||
res.append({name:value for name,value in zip(col_names, row)})
|
col_names = [col.name for col in local_cr.description]
|
||||||
return res
|
for row in local_cr.fetchall():
|
||||||
except Exception:
|
res.append({name:value for name, value in zip(col_names, row)})
|
||||||
return []
|
return res
|
||||||
|
|
||||||
def process_logs(self, build_ids=None):
|
def process_logs(self, build_ids=None):
|
||||||
"""move logs from host to the leader"""
|
"""move logs from host to the leader"""
|
||||||
@ -209,7 +209,10 @@ class Host(models.Model):
|
|||||||
local_log_ids = []
|
local_log_ids = []
|
||||||
for log in ir_logs:
|
for log in ir_logs:
|
||||||
if log['dbname'] and '-' in log['dbname']:
|
if log['dbname'] and '-' in log['dbname']:
|
||||||
logs_by_build_id[int(log['dbname'].split('-', maxsplit=1)[0])].append(log)
|
try:
|
||||||
|
logs_by_build_id[int(log['dbname'].split('-', maxsplit=1)[0])].append(log)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
local_log_ids.append(log['id'])
|
local_log_ids.append(log['id'])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user