class TpCommon::FileStorage::Downloaders::Private

Pull and read a files from storage service. Included retry mechanism.

Public Instance Methods

download(file_key) click to toggle source

Pull a file with provided key. Return a Fog file object www.rubydoc.info/github/fog/fog-aws/Fog/Storage/AWS/File @param file_key [String]

# File lib/tp_common/file_storage/downloaders/private.rb, line 11
def download(file_key)
  retried_count = 0
  begin
    directory.files.get(mask_key(file_key)).tap do |file|
      raise FileStorage::Errors::FileNotFound.new("Could not find file: #{file_key}") unless file
    end
  rescue ::Fog::Errors::Error => error
    retried_count += 1
    retry if retried_count < MAX_RETRIES
    raise FileStorage::Errors::FailedToDownload.new("Failed to download file via fog: #{error.message}")
  end
end
exists?(file_key) click to toggle source

@param file_key [String]

# File lib/tp_common/file_storage/downloaders/private.rb, line 31
def exists?(file_key)
  !!directory.files.head(mask_key(file_key))
end
read(file_key) click to toggle source

Same as download but return file content @param file_key [String]

# File lib/tp_common/file_storage/downloaders/private.rb, line 26
def read(file_key)
  download(mask_key(file_key)).body
end