Tasks

class queued_storage.tasks.Transfer

The default task. Transfers a file to a remote location. The actual transfer is implemented in the remote backend.

To use a different task, pass it into the backend:

from queued_storage.backends import QueuedS3BotoStorage

s3_delete_storage = QueuedS3BotoStorage(
    task='queued_storage.tasks.TransferAndDelete')

# later, in model definition:
image = models.ImageField(storage=s3_delete_storage)

The result should be True if the transfer was successful, or False if unsuccessful. In the latter case the task will be retried.

You can subclass the Transfer class to customize the behaviour, to do something like this:

from queued_storage.tasks import Transfer

class TransferAndNotify(Transfer):
    def transfer(self, *args, **kwargs):
        result = super(TransferAndNotify, self).transfer(*args, **kwargs)
        if result:
            # call the (imaginary) notify function with the result
            notify(result)
        return result
max_retries = 5

The number of retries if unsuccessful (default: see QUEUED_STORAGE_RETRIES)

default_retry_delay = 60

The delay between each retry in seconds (default: see QUEUED_STORAGE_RETRY_DELAY)

run(name, cache_key, local_path, remote_path, local_options, remote_options, **kwargs)

The main work horse of the transfer task. Calls the transfer method with the local and remote storage backends as given with the parameters.

Parameters:
  • name (str) – name of the file to transfer
  • local_path (str) – local storage class to transfer from
  • local_options (dict) – options of the local storage class
  • remote_path (str) – remote storage class to transfer to
  • remote_options (dict) – options of the remote storage class
  • cache_key (str) – cache key to set after a successful transfer
Return type:

task result

transfer(name, local, remote, **kwargs)

Transfers the file with the given name from the local to the remote storage backend.

Parameters:
  • name – The name of the file to transfer
  • local – The local storage backend instance
  • remote – The remote storage backend instance
Returns:

True when the transfer succeeded, False if not. Retries the task when returning False

Return type:

bool

acks_late = False
delivery_mode = 2
exchange_type = u'direct'
ignore_result = False
name = u'queued_storage.tasks.Transfer'
rate_limit = None
reject_on_worker_lost = None
request_stack = <celery.utils.threads._LocalStack object>
serializer = u'json'
store_errors_even_if_ignored = False
track_started = False
typing = True
class queued_storage.tasks.TransferAndDelete

A Transfer subclass which deletes the file with the given name using the local storage if the transfer was successful.

transfer(name, local, remote, **kwargs)
name = u'queued_storage.tasks.TransferAndDelete'
rate_limit = None
reject_on_worker_lost = None