[server] Only register "clean_sessions" looping tasks if repository has a tasks manager
This prepares for calling Repository's _prepare_startup() in bootstrap() so
that repository instances without a tasks manager running can still have their
'server_startup' hooks triggered (this is particularly useful for BFSS
storages).
--- a/cubicweb/server/repository.py Fri Feb 24 10:16:17 2017 +0100
+++ b/cubicweb/server/repository.py Tue Feb 28 16:05:00 2017 +0100
@@ -410,13 +410,12 @@
# call instance level initialisation hooks
self.hm.call_hooks('server_startup', repo=self)
# register a task to cleanup expired session
- 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)
+ if self._tasks_manager is not None:
+ 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)
+ self._tasks_manager.add_looping_task(cleanup_session_interval,
+ self.clean_sessions)
def start_looping_tasks(self):
"""Actual "Repository as a server" startup.