mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[FIX] runbot: catch exceptions during db drop
When the runbot tries to drop a local database, if the that raises an exception, it goes in a loop failure. It mays happen for example if someone forgot to close a psql during an investigation :-) With this commit, the exceptions are catched and at least the database name is logged.
This commit is contained in:
parent
7523dc8000
commit
236554b588
@ -906,17 +906,28 @@ class BuildResult(models.Model):
|
|||||||
return sorted(modules_to_install)
|
return sorted(modules_to_install)
|
||||||
|
|
||||||
def _local_pg_dropdb(self, dbname):
|
def _local_pg_dropdb(self, dbname):
|
||||||
with local_pgadmin_cursor() as local_cr:
|
msg = ''
|
||||||
pid_col = 'pid' if local_cr.connection.server_version >= 90200 else 'procpid'
|
try:
|
||||||
query = 'SELECT pg_terminate_backend({}) FROM pg_stat_activity WHERE datname=%s'.format(pid_col)
|
with local_pgadmin_cursor() as local_cr:
|
||||||
local_cr.execute(query, [dbname])
|
pid_col = 'pid' if local_cr.connection.server_version >= 90200 else 'procpid'
|
||||||
local_cr.execute('DROP DATABASE IF EXISTS "%s"' % dbname)
|
query = 'SELECT pg_terminate_backend({}) FROM pg_stat_activity WHERE datname=%s'.format(pid_col)
|
||||||
# cleanup filestore
|
local_cr.execute(query, [dbname])
|
||||||
datadir = appdirs.user_data_dir()
|
local_cr.execute('DROP DATABASE IF EXISTS "%s"' % dbname)
|
||||||
paths = [os.path.join(datadir, pn, 'filestore', dbname) for pn in 'OpenERP Odoo'.split()]
|
# cleanup filestore
|
||||||
cmd = ['rm', '-rf'] + paths
|
datadir = appdirs.user_data_dir()
|
||||||
_logger.info(' '.join(cmd))
|
paths = [os.path.join(datadir, pn, 'filestore', dbname) for pn in 'OpenERP Odoo'.split()]
|
||||||
subprocess.call(cmd)
|
cmd = ['rm', '-rf'] + paths
|
||||||
|
_logger.info(' '.join(cmd))
|
||||||
|
subprocess.call(cmd)
|
||||||
|
except psycopg2.errors.InsufficientPrivilege:
|
||||||
|
msg = f"Insuficient priveleges to drop local database '{dbname}'"
|
||||||
|
_logger.warning(msg)
|
||||||
|
except Exception as e:
|
||||||
|
msg = f"Failed to drop local logs database : {dbname} with exception: {e}"
|
||||||
|
_logger.exception(msg)
|
||||||
|
if msg:
|
||||||
|
host_name = self.env['runbot.host']._get_current_name()
|
||||||
|
self.env['runbot.runbot'].warning(f'Host {host_name}: {msg}')
|
||||||
|
|
||||||
def _local_pg_createdb(self, dbname):
|
def _local_pg_createdb(self, dbname):
|
||||||
icp = self.env['ir.config_parameter']
|
icp = self.env['ir.config_parameter']
|
||||||
|
Loading…
Reference in New Issue
Block a user