mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] Clean old, unused and not deleted runbot builds databases
This commit is contained in:
parent
b04488f22f
commit
65e86b564e
@ -1171,6 +1171,23 @@ class runbot_build(osv.osv):
|
||||
path = os.path.join(build_dir, b)
|
||||
if b not in actives and os.path.isdir(path):
|
||||
shutil.rmtree(path)
|
||||
|
||||
# cleanup old unused databases
|
||||
cr.execute("select id from runbot_build where state in ('testing', 'running')")
|
||||
db_ids = [id[0] for id in cr.fetchall()]
|
||||
if db_ids:
|
||||
with local_pgadmin_cursor() as local_cr:
|
||||
local_cr.execute("""
|
||||
SELECT datname
|
||||
FROM pg_database
|
||||
WHERE pg_get_userbyid(datdba) = current_user
|
||||
AND datname ~ '^[0-9]+-.*'
|
||||
AND SUBSTRING(datname, '^([0-9]+)-.*')::int not in %s
|
||||
|
||||
""", [tuple(db_ids)])
|
||||
to_delete = local_cr.fetchall()
|
||||
for db, in to_delete:
|
||||
self._local_pg_dropdb(cr, uid, db)
|
||||
|
||||
def kill(self, cr, uid, ids, result=None, context=None):
|
||||
for build in self.browse(cr, uid, ids, context=context):
|
||||
|
Loading…
Reference in New Issue
Block a user