Sha256: 7324ab3bf12646ed7bffc8b9dae80927a06aa3077732156beb7a7fbe8a14e432

Contents?: true

Size: 1.46 KB

Versions: 38

Compression:

Stored size: 1.46 KB

Contents

module CloudCrowd
  class AssetStore
    
    # 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.
    module FilesystemStore
      
      DEFAULT_STORAGE_PATH = '/tmp/cloud_crowd_storage'
      
      attr_reader :local_storage_path
      
      # Make sure that local storage exists and is writeable before starting.
      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
      
      # Save a file to somewhere semi-persistent on the filesystem. To use, 
      # configure <tt>:storage: 'filesystem'</tt> in *config.yml*, as well as
      # <tt>:local_storage_path:</tt>.
      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
      
      # Remove all of a Job's result files from the filesystem.
      def cleanup(job)
        path = "#{@local_storage_path}/#{job.action}/job_#{job.id}"
        FileUtils.rm_r(path) if File.exists?(path)
      end
    end
    
  end
end

Version data entries

38 entries across 38 versions & 3 rubygems

Version Path
cloud-crowd-0.7.6 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.5 lib/cloud_crowd/asset_store/filesystem_store.rb
documentcloud-cloud-crowd-0.2.0 lib/cloud_crowd/asset_store/filesystem_store.rb
documentcloud-cloud-crowd-0.2.1 lib/cloud_crowd/asset_store/filesystem_store.rb
documentcloud-cloud-crowd-0.2.2 lib/cloud_crowd/asset_store/filesystem_store.rb
documentcloud-cloud-crowd-0.2.3 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.3 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.2 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.2.beta lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.2.pre3 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.2.pre2 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.2.pre lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.1 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.0 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.7.0.pre lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.6.2 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.6.1 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.6.0 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.5.2 lib/cloud_crowd/asset_store/filesystem_store.rb
cloud-crowd-0.5.0 lib/cloud_crowd/asset_store/filesystem_store.rb