Module: CloudCrowd::AssetStore::CloudfilesStore

Defined in:
lib/cloud_crowd/asset_store/cloudfiles_store.rb

Overview

The CloudFilesStore is an implementation of an AssetStore that uses a Rackspace Cloud

Instance Method Summary (collapse)

Instance Method Details

- (Object) cleanup(job)

Remove all of a Job's resulting files from Cloud Files, both intermediate and finished.



29
30
31
32
33
34
35
36
37
# File 'lib/cloud_crowd/asset_store/cloudfiles_store.rb', line 29

def cleanup(job)
  @container.objects(:prefix => "#{job.action}/job_#{job.id}").each do |object|
    begin
      @container.delete_object object
    rescue
      log "failed to delete #{job.action}/job_#{job.id}"
    end
  end
end

- (Object) save(local_path, save_path)

Save a finished file from local storage to Cloud Files.



22
23
24
25
26
# File 'lib/cloud_crowd/asset_store/cloudfiles_store.rb', line 22

def save(local_path, save_path)
  object = @container.create_object save_path, true
  object.load_from_filename local_path
  object.public_url
end

- (Object) setup

Configure Rackspace Cloud and connect



10
11
12
13
14
15
16
17
18
19
# File 'lib/cloud_crowd/asset_store/cloudfiles_store.rb', line 10

def setup
  username  = CloudCrowd.config[:cloudfiles_username]
  api_key   = CloudCrowd.config[:cloudfiles_api_key]
  container = CloudCrowd.config[:cloudfiles_container]
  valid_conf  = [username, api_key, container].all? {|s| s.is_a? String }
  raise Error::MissingConfiguration, "A Rackspace Cloud Files account must be configured in 'config.yml' before 'cloudfiles' storage can be used" unless valid_conf

  @cloud = CloudFiles::Connection.new(username, api_key)
  @container = @cloud.container container
end