""" Preload a registry, and start the cron."""
try:
update_module = True if openerp.tools.config['init'] or openerp.tools.config['update'] else False
- db, registry = openerp.pooler.get_db_and_pool(dbname, update_module=update_module, pooljobs=False)
-
- # jobs will start to be processed later, when openerp.cron.start_master_thread() is called by openerp.service.start_services()
- registry.schedule_cron_jobs()
+ db, registry = openerp.pooler.get_db_and_pool(dbname,update_module=update_module)
except Exception:
_logger.exception('Failed to initialize database `%s`.', dbname)
""" Preload a registry, possibly run a test file, and start the cron."""
try:
config = openerp.tools.config
- db, registry = 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'])
cr = db.cursor()
_logger.info('loading test file %s', test_file)
openerp.tools.convert_yaml_import(cr, 'base', file(test_file), 'test', {}, 'test', True)
self.db_name = db_name
self.db = openerp.sql_db.db_connect(db_name)
- # In monoprocess cron jobs flag (pooljobs)
- self.cron = False
+ # Indicates that the registry is
+ self.ready = False
# Inter-process signaling (used only when openerp.multi_process is True):
# The `base_registry_signaling` sequence indicates the whole registry
models_to_load.append(model._name)
return [self.models[m] for m in models_to_load]
- def schedule_cron_jobs(self):
- """ Make the cron thread care about this registry/database jobs.
- This will initiate the cron thread to check for any pending jobs for
- this registry/database as soon as possible. Then it will continuously
- monitor the ir.cron model for future jobs. See openerp.cron for
- details.
- """
- self.cron = True
-
def clear_caches(self):
""" Clear the caches
This clears the caches associated to methods decorated with
registries_lock = threading.RLock()
@classmethod
- def get(cls, db_name, force_demo=False, status=None, update_module=False,
- pooljobs=True):
+ def get(cls, db_name, force_demo=False, status=None, update_module=False):
""" Return a registry for a given database name."""
try:
return cls.registries[db_name]
except KeyError:
return cls.new(db_name, force_demo, status,
- update_module, pooljobs)
+ update_module)
@classmethod
def new(cls, db_name, force_demo=False, status=None,
- update_module=False, pooljobs=True):
+ update_module=False):
""" Create and return a new registry for a given database name.
The (possibly) previous registry for that database name is discarded.
finally:
cr.close()
- if pooljobs:
- registry.schedule_cron_jobs()
+ registry.ready = True
return registry
@classmethod
def check_registry_signaling(cls, db_name):
if openerp.multi_process and db_name in cls.registries:
- registry = cls.get(db_name, pooljobs=False)
+ registry = cls.get(db_name)
cr = registry.db.cursor()
try:
cr.execute("""
# database has been updated by another process).
if registry.base_registry_signaling_sequence != r:
_logger.info("Reloading the model registry after database signaling.")
- # Don't run the cron in the Gunicorn worker.
- registry = cls.new(db_name, pooljobs=False)
+ registry = cls.new(db_name)
registry.base_registry_signaling_sequence = r
# Check if the model caches must be invalidated (e.g. after a write
# occured on another process). Don't clear right after a registry
if openerp.multi_process and db_name in cls.registries:
# Check the registries if any cache has been cleared and signal it
# through the database to other processes.
- registry = cls.get(db_name, pooljobs=False)
+ registry = cls.get(db_name)
if registry.any_cache_cleared():
_logger.info("At least one model cache has been cleared, signaling through the database.")
cr = registry.db.cursor()
@classmethod
def signal_registry_change(cls, db_name):
if openerp.multi_process and db_name in cls.registries:
- registry = cls.get(db_name, pooljobs=False)
+ registry = cls.get(db_name)
cr = registry.db.cursor()
r = 1
try:
from openerp.modules.registry import RegistryManager
-def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False, pooljobs=True):
+def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
"""Create and return a database connection and a newly initialized registry."""
- registry = RegistryManager.get(db_name, force_demo, status, update_module, pooljobs)
+ registry = RegistryManager.get(db_name, force_demo, status, update_module)
return registry.db, registry
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."""
- # preserve previous `cron-active` status of registry if it existed already
- previous_registry = RegistryManager.registries.get(db_name)
- cron_active = previous_registry and previous_registry.cron or False
-
- registry = RegistryManager.new(db_name, force_demo, status, update_module, pooljobs=cron_active)
+ registry = RegistryManager.new(db_name, force_demo, status, update_module)
return registry.db, registry
-
def get_db(db_name):
"""Return a database connection. The corresponding registry is initialized."""
return get_db_and_pool(db_name)[0]