Commits

mwolf76 committed 786d815

Added temporary persistence to avoid multiple uploads

Comments (0)

Files changed (1)

storages/backends/moka.py

     """Moka custom storage."""
 
     def __init__(self):
+
         logger.info("Initializing storage: %s", self)
+
         super(MokaStorage, self).__init__(
             local='django.core.files.storage.FileSystemStorage',
             remote='storages.backends.mosso.CloudFilesStorage')
         logger.info("Connection to redis is now active: %s.", self._redis)
 
     def _get_local_storage(self, name):
+        """Local storage retrieval."""
 
         if (self.local.exists(name)):
-            logger.info(
-                "Retrying upload for file '%s'", name
-            )
-            self._send_task(name)
+            if not self._redis.get(name):  # avoid firing multiple tasks
+                logger.info("Retrying upload for file '%s'", name)
+                self._send_task(name)
 
         else:
             # ok, here we're in trouble :-(
         return self.local
 
     def get_storage(self, name):
-        cache_result = self._redis.sismember(settings.REMOTE, name)
+        """Storage retrieval."""
 
-        if cache_result:
+        if self._redis.sismember(settings.REMOTE, name):
             logger.info("Cache hit ok for file '%s'", name)
             return self.remote