Permalink
Browse files

Retrying the upload to remote storage when it fails

  • Loading branch information...
1 parent 357a07c commit 7d7d81a6d5c1f3123712e0ad010623da738d976a @codekoala committed Oct 30, 2010
Showing with 14 additions and 4 deletions.
  1. +14 −4 queued_storage/tasks.py
View
18 queued_storage/tasks.py
@@ -5,11 +5,21 @@
from celery.task import Task
class SaveToRemoteTask(Task):
- def run(self, name, local, remote, cache_key):
+ max_retries = 5
+ default_retry_delay = 60
+
+ def run(self, name, local, remote, cache_key, **kwargs):
local_storage = get_storage_class(local)()
remote_storage = get_storage_class(remote)()
- remote_storage.save(name, local_storage.open(name))
+
+ try:
+ remote_storage.save(name, local_storage.open(name))
+ except:
+ # something went wrong while uploading the file, retry
+ self.retry([name, local, remote, cache_key], **kwargs)
+ return False
+
cache.set(cache_key, True)
return True
-
-tasks.register(SaveToRemoteTask)
+
+tasks.register(SaveToRemoteTask)

0 comments on commit 7d7d81a

Please sign in to comment.