[repository] move task manager instantiation outside repository.
Repository callers are in charge of providing a task manager.
The task manager is optional when the repository is not a server. This
part is not really expected to work well yet. But we aim to remove all task
management responsibilities from the Repository object.
--- a/dbapi.py Tue Mar 20 18:24:46 2012 +0100
+++ b/dbapi.py Tue Mar 20 18:25:06 2012 +0100
@@ -100,7 +100,9 @@
if method == 'inmemory':
# get local access to the repository
from cubicweb.server.repository import Repository
- return Repository(config, vreg=vreg)
+ from cubicweb.server.utils import TasksManager
+ return Repository(config, TasksManager(), vreg=vreg)
+
else: # method == 'pyro'
# resolve the Pyro object
from logilab.common.pyro_ext import ns_get_proxy, get_proxy
--- a/server/repository.py Tue Mar 20 18:24:46 2012 +0100
+++ b/server/repository.py Tue Mar 20 18:25:06 2012 +0100
@@ -142,12 +142,12 @@
XXX protect pyro access
"""
- def __init__(self, config, vreg=None):
+ def __init__(self, config, tasks_manager=None, vreg=None):
self.config = config
if vreg is None:
vreg = cwvreg.CWRegistryStore(config)
self.vreg = vreg
- self._tasks_manager = utils.TasksManager()
+ self._tasks_manager = tasks_manager
self.pyro_registered = False
self.pyro_uri = None
@@ -368,6 +368,7 @@
self.cleanup_session_time = self.config['cleanup-session-time'] or 60 * 60 * 24
assert self.cleanup_session_time > 0
cleanup_session_interval = min(60*60, self.cleanup_session_time / 3)
+ assert self._tasks_manager is not None, "This Repository is not intended to be used as a server"
self._tasks_manager.add_looping_task(cleanup_session_interval,
self.clean_sessions)
@@ -382,6 +383,7 @@
XXX __init__ or in external codes (various server managers).
"""
self._prepare_startup()
+ assert self._tasks_manager is not None, "This Repository is not intended to be used as a server"
self._tasks_manager.start()
def looping_task(self, interval, func, *args):
@@ -390,6 +392,7 @@
looping tasks can only be registered during repository initialization,
once done this method will fail.
"""
+ assert self._tasks_manager is not None, "This Repository is not intended to be used as a server"
self._tasks_manager.add_looping_task(interval, func, *args)
def threaded_task(self, func):
@@ -424,7 +427,8 @@
assert not self.shutting_down, 'already shutting down'
self.shutting_down = True
self.system_source.shutdown()
- self._tasks_manager.stop()
+ if self._tasks_manager is not None:
+ self._tasks_manager.stop()
for thread in self._running_threads:
self.info('waiting thread %s...', thread.getName())
thread.join()
--- a/server/server.py Tue Mar 20 18:24:46 2012 +0100
+++ b/server/server.py Tue Mar 20 18:25:06 2012 +0100
@@ -26,6 +26,7 @@
from time import localtime, mktime
from cubicweb.cwconfig import CubicWebConfiguration
+from cubicweb.server.utils import TasksManager
from cubicweb.server.repository import Repository
class Finished(Exception):
@@ -77,7 +78,7 @@
def __init__(self, config):
"""make the repository available as a PyRO object"""
self.config = config
- self.repo = Repository(config)
+ self.repo = Repository(config, TasksManager())
self.ns = None
self.quiting = None
# event queue