[server] Only register "clean_sessions" looping tasks if repository has a tasks manager
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 28 Feb 2017 16:05:00 +0100
changeset 11985 08398df041b4
parent 11984 55f57038e553
child 11986 4d414ecf8416
[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).
cubicweb/server/repository.py
--- 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.