[hooks] internal_session -> internal_cnx (including a typo)
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Tue, 03 Jun 2014 17:01:11 +0200
changeset 9775 614f8f3d2a35
parent 9774 b7b71be569cf
child 9776 d5413f2453a1
[hooks] internal_session -> internal_cnx (including a typo)
hooks/__init__.py
--- a/hooks/__init__.py	Fri May 02 14:26:14 2014 +0200
+++ b/hooks/__init__.py	Tue Jun 03 17:01:11 2014 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -34,14 +34,11 @@
         lifetime = timedelta(days=self.repo.config['keep-transaction-lifetime'])
         def cleanup_old_transactions(repo=self.repo, lifetime=lifetime):
             mindate = datetime.now() - lifetime
-            session = repo.internal_session()
-            try:
-                session.system_sql(
+            with repo.internal_cnx() as cnx:
+                cnx.system_sql(
                     'DELETE FROM transactions WHERE tx_time < %(time)s',
                     {'time': mindate})
-                session.commit()
-            finally:
-                session.close()
+                cnx.commit()
         if self.repo.config['undo-enabled']:
             self.repo.looping_task(60*60*24, cleanup_old_transactions,
                                    self.repo)
@@ -60,7 +57,7 @@
                     or not repo.config.source_enabled(source)
                     or not source.config['synchronize']):
                     continue
-                with repo.internal_connection() as cnx:
+                with repo.internal_cnx() as cnx:
                     try:
                         source.pull_data(cnx)
                     except Exception as exc:
@@ -79,12 +76,9 @@
                 if (uri == 'system'
                     or not repo.config.source_enabled(source)):
                     continue
-                session = repo.internal_session()
-                try:
+                with repo.internal_cnx() as cnx:
                     mindate = datetime.now() - timedelta(seconds=source.config['logs-lifetime'])
-                    session.execute('DELETE CWDataImport X WHERE X start_timestamp < %(time)s',
+                    cnx.execute('DELETE CWDataImport X WHERE X start_timestamp < %(time)s',
                                     {'time': mindate})
-                    session.commit()
-                finally:
-                    session.close()
+                    cnx.commit()
         self.repo.looping_task(60*60*24, expire_dataimports, self.repo)