[startup hook/looping tasks] separated hook for each looping task to ease modification from cubes. Closes #2517096 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 08 Nov 2012 11:43:11 +0100
branchstable
changeset 8587 bde0501e0251
parent 8586 bc74608d2003
child 8588 22af622e6e24
[startup hook/looping tasks] separated hook for each looping task to ease modification from cubes. Closes #2517096
hooks/__init__.py
--- a/hooks/__init__.py	Thu Nov 08 11:40:24 2012 +0100
+++ b/hooks/__init__.py	Thu Nov 08 11:43:11 2012 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -23,9 +23,9 @@
 
 from cubicweb.server import hook
 
-class ServerStartupHook(hook.Hook):
-    """task to cleanup expirated auth cookie entities"""
-    __regid__ = 'cw.start-looping-tasks'
+class TransactionsCleanupStartupHook(hook.Hook):
+    """start task to cleanup transaction data"""
+    __regid__ = 'cw.looping-tasks.transactions-cleanup'
     events = ('server_startup',)
 
     def __call__(self):
@@ -49,6 +49,13 @@
         if self.repo.config['undo-enabled']:
             self.repo.looping_task(60*60*24, cleanup_old_transactions,
                                    self.repo)
+
+class UpdateFeedsStartupHook(hook.Hook):
+    """start task to update datafeed based sources"""
+    __regid__ = 'cw.looping-tasks.update-feeds'
+    events = ('server_startup',)
+
+    def __call__(self):
         def update_feeds(repo):
             # don't iter on repo.sources which doesn't include copy based
             # sources (the one we're looking for)
@@ -66,6 +73,13 @@
                     session.close()
         self.repo.looping_task(60, update_feeds, self.repo)
 
+
+class DataImportsCleanupStartupHook(hook.Hook):
+    """start task to cleanup old data imports (ie datafeed import logs)"""
+    __regid__ = 'cw.looping-tasks.dataimports-cleanup'
+    events = ('server_startup',)
+
+    def __call__(self):
         def expire_dataimports(repo=self.repo):
             for source in repo.sources_by_eid.itervalues():
                 if (not source.copy_based_source
@@ -74,7 +88,8 @@
                 session = repo.internal_session()
                 try:
                     mindate = datetime.now() - timedelta(seconds=source.config['logs-lifetime'])
-                    session.execute('DELETE CWDataImport X WHERE X start_timestamp < %(time)s', {'time': mindate})
+                    session.execute('DELETE CWDataImport X WHERE X start_timestamp < %(time)s',
+                                    {'time': mindate})
                     session.commit()
                 finally:
                     session.close()