[IMP] registry: whene deleting a registry, also delete its cache and cron.
bzr revid: vmt@openerp.com-20110713153521-isn9bllnggbxwi0z
This commit is contained in:
parent
6f5eb6b91e
commit
b5daffc115
|
@ -100,7 +100,7 @@ if not ( config["stop_after_init"] or \
|
||||||
|
|
||||||
if config['db_name']:
|
if config['db_name']:
|
||||||
for dbname in config['db_name'].split(','):
|
for dbname in config['db_name'].split(','):
|
||||||
db, pool = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
|
db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=config['init'] or config['update'], pooljobs=False)
|
||||||
cr = db.cursor()
|
cr = db.cursor()
|
||||||
|
|
||||||
if config["test_file"]:
|
if config["test_file"]:
|
||||||
|
@ -109,7 +109,7 @@ if config['db_name']:
|
||||||
cr.rollback()
|
cr.rollback()
|
||||||
|
|
||||||
# jobs will start to be processed later, when start_agent below is called.
|
# jobs will start to be processed later, when start_agent below is called.
|
||||||
pool.get('ir.cron').restart(db.dbname)
|
registry.start_cron_thread()
|
||||||
|
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
|
@ -218,6 +218,7 @@ def quit():
|
||||||
# and would present the forced shutdown
|
# and would present the forced shutdown
|
||||||
thread.join(0.05)
|
thread.join(0.05)
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
openerp.modules.registry.RegistryManager.delete_all()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if config['pidfile']:
|
if config['pidfile']:
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
|
|
||||||
import openerp.sql_db
|
import openerp.sql_db
|
||||||
import openerp.osv.orm
|
import openerp.osv.orm
|
||||||
|
import openerp.netsvc
|
||||||
|
import openerp.tools
|
||||||
|
|
||||||
|
|
||||||
class Registry(object):
|
class Registry(object):
|
||||||
|
@ -82,6 +84,9 @@ class Registry(object):
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def start_cron_thread(self):
|
||||||
|
self.get('ir.cron').restart(self.db.dbname)
|
||||||
|
|
||||||
|
|
||||||
class RegistryManager(object):
|
class RegistryManager(object):
|
||||||
""" Model registries manager.
|
""" Model registries manager.
|
||||||
|
@ -143,16 +148,34 @@ class RegistryManager(object):
|
||||||
cr.close()
|
cr.close()
|
||||||
|
|
||||||
if pooljobs:
|
if pooljobs:
|
||||||
registry.get('ir.cron').restart(registry.db.dbname)
|
registry.start_cron_thread()
|
||||||
|
|
||||||
return registry
|
return registry
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, db_name):
|
def delete(cls, db_name):
|
||||||
""" Delete the registry linked to a given database. """
|
""" Delete the registry linked to a given database.
|
||||||
|
|
||||||
|
This also cleans the associated caches. For good measure this also
|
||||||
|
cancels the associated cron job. But please note that the cron job can
|
||||||
|
be running and take some time before ending, and that you should not
|
||||||
|
remove a registry if it can still be used by some thread. So it might
|
||||||
|
be necessary to call yourself openerp.netsvc.Agent.cancel(db_name) and
|
||||||
|
and join (i.e. wait for) the thread.
|
||||||
|
|
||||||
|
"""
|
||||||
if db_name in cls.registries:
|
if db_name in cls.registries:
|
||||||
del cls.registries[db_name]
|
del cls.registries[db_name]
|
||||||
|
openerp.tools.cache.clean_caches_for_db(db_name)
|
||||||
|
openerp.netsvc.Agent.cancel(db_name)
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_all(cls):
|
||||||
|
""" Delete all the registries. """
|
||||||
|
for db_name in cls.registries.keys():
|
||||||
|
cls.delete(db_name)
|
||||||
|
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
|
@ -34,11 +34,6 @@ def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False,
|
||||||
return registry.db, registry
|
return registry.db, registry
|
||||||
|
|
||||||
|
|
||||||
def delete_pool(db_name):
|
|
||||||
"""Delete an existing registry."""
|
|
||||||
RegistryManager.delete(db_name)
|
|
||||||
|
|
||||||
|
|
||||||
def restart_pool(db_name, force_demo=False, status=None, update_module=False):
|
def restart_pool(db_name, force_demo=False, status=None, update_module=False):
|
||||||
"""Delete an existing registry and return a database connection and a newly initialized registry."""
|
"""Delete an existing registry and return a database connection and a newly initialized registry."""
|
||||||
registry = RegistryManager.new(db_name, force_demo, status, update_module, True)
|
registry = RegistryManager.new(db_name, force_demo, status, update_module, True)
|
||||||
|
|
|
@ -161,8 +161,8 @@ class db(netsvc.ExportService):
|
||||||
raise Exception, e
|
raise Exception, e
|
||||||
|
|
||||||
def exp_drop(self, db_name):
|
def exp_drop(self, db_name):
|
||||||
|
openerp.modules.registry.RegistryManager.delete(db_name)
|
||||||
sql_db.close_db(db_name)
|
sql_db.close_db(db_name)
|
||||||
openerp.netsvc.Agent.cancel(db_name)
|
|
||||||
logger = netsvc.Logger()
|
logger = netsvc.Logger()
|
||||||
|
|
||||||
db = sql_db.db_connect('template1')
|
db = sql_db.db_connect('template1')
|
||||||
|
@ -264,8 +264,8 @@ class db(netsvc.ExportService):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def exp_rename(self, old_name, new_name):
|
def exp_rename(self, old_name, new_name):
|
||||||
|
openerp.modules.registry.RegistryManager.delete(old_name)
|
||||||
sql_db.close_db(old_name)
|
sql_db.close_db(old_name)
|
||||||
openerp.netsvc.Agent.cancel(db_name)
|
|
||||||
logger = netsvc.Logger()
|
logger = netsvc.Logger()
|
||||||
|
|
||||||
db = sql_db.db_connect('template1')
|
db = sql_db.db_connect('template1')
|
||||||
|
|
|
@ -429,9 +429,8 @@ def db_connect(db_name):
|
||||||
return Connection(_Pool, db_name)
|
return Connection(_Pool, db_name)
|
||||||
|
|
||||||
def close_db(db_name):
|
def close_db(db_name):
|
||||||
""" You might want to call openerp.netsvc.Agent.cancel(db_name) along this function."""
|
""" You might want to call openerp.modules.registry.RegistryManager.delete(db_name) along this function."""
|
||||||
_Pool.close_all(dsn(db_name))
|
_Pool.close_all(dsn(db_name))
|
||||||
tools.cache.clean_caches_for_db(db_name)
|
|
||||||
ct = currentThread()
|
ct = currentThread()
|
||||||
if hasattr(ct, 'dbname'):
|
if hasattr(ct, 'dbname'):
|
||||||
delattr(ct, 'dbname')
|
delattr(ct, 'dbname')
|
||||||
|
|
Loading…
Reference in New Issue