Module: CloudCrowd::AssetStore::FilesystemStore

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

Overview

The FilesystemStore is an implementation of the AssetStore, good only for use in development, testing, if you're only running a single-machine installation, or are using a networked drive.

Constant Summary

DEFAULT_STORAGE_PATH =
'/tmp/cloud_crowd_storage'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) local_storage_path (readonly)

Returns the value of attribute local_storage_path



11
12
13
# File 'lib/cloud_crowd/asset_store/filesystem_store.rb', line 11

def local_storage_path
  @local_storage_path
end

Instance Method Details

- (Object) cleanup(job)

Remove all of a Job's result files from the filesystem.



32
33
34
35
# File 'lib/cloud_crowd/asset_store/filesystem_store.rb', line 32

def cleanup(job)
  path = "#{@local_storage_path}/#{job.action}/job_#{job.id}"
  FileUtils.rm_r(path) if File.exists?(path)
end

- (Object) save(local_path, save_path)

Save a file to somewhere semi-persistent on the filesystem. To use, configure :storage: 'filesystem' in config.yml, as well as :local_storage_path:.



23
24
25
26
27
28
29
# File 'lib/cloud_crowd/asset_store/filesystem_store.rb', line 23

def save(local_path, save_path)
  save_path = File.join(@local_storage_path, save_path)
  save_dir = File.dirname(save_path)
  FileUtils.mkdir_p save_dir unless File.exists? save_dir
  FileUtils.cp(local_path, save_path)
  "file://#{File.expand_path(save_path)}"
end

- (Object) setup

Make sure that local storage exists and is writeable before starting.



14
15
16
17
18
# File 'lib/cloud_crowd/asset_store/filesystem_store.rb', line 14

def setup
  lsp = @local_storage_path = CloudCrowd.config[:local_storage_path] || DEFAULT_STORAGE_PATH
  FileUtils.mkdir_p(lsp) unless File.exists?(lsp)
  raise Error::StorageNotWritable, "#{lsp} is not writable" unless File.writable?(lsp)
end