c-c source-sync now actually force synchronization
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 16 Feb 2016 10:52:00 +0100
changeset 11125 e717da3dc164
parent 11099 5fdbf6f2db88
child 11126 9bacaf91afbc
c-c source-sync now actually force synchronization as advertized by its help message. This was because "force" argument wasn't considered by acquire_synchronization_lock().
cubicweb/server/sources/datafeed.py
--- a/cubicweb/server/sources/datafeed.py	Fri Jan 29 17:22:25 2016 +0100
+++ b/cubicweb/server/sources/datafeed.py	Tue Feb 16 10:52:00 2016 +0100
@@ -171,14 +171,18 @@
                     {'x': self.eid, 'date': self.latest_retrieval})
         cnx.commit()
 
-    def acquire_synchronization_lock(self, cnx):
+    def acquire_synchronization_lock(self, cnx, force=False):
         # XXX race condition until WHERE of SET queries is executed using
         # 'SELECT FOR UPDATE'
         now = datetime.now(tz=utc)
+        if force:
+            maxdt = now
+        else:
+            maxdt = now - self.max_lock_lifetime
         if not cnx.execute(
-            'SET X in_synchronization %(now)s WHERE X eid %(x)s, '
-            'X in_synchronization NULL OR X in_synchronization < %(maxdt)s',
-            {'x': self.eid, 'now': now, 'maxdt': now - self.max_lock_lifetime}):
+                'SET X in_synchronization %(now)s WHERE X eid %(x)s, '
+                'X in_synchronization NULL OR X in_synchronization < %(maxdt)s',
+                {'x': self.eid, 'now': now, 'maxdt': maxdt}):
             self.error('concurrent synchronization detected, skip pull')
             cnx.commit()
             return False
@@ -198,7 +202,7 @@
         """
         if not force and self.fresh():
             return {}
-        if not self.acquire_synchronization_lock(cnx):
+        if not self.acquire_synchronization_lock(cnx, force):
             return {}
         try:
             return self._pull_data(cnx, force, raise_on_error)