Class: S3Poller::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/s3poller/downloader.rb

Instance Method Summary collapse

Constructor Details

#initialize(local_path) ⇒ Downloader

Returns a new instance of Downloader.



5
6
7
# File 'lib/s3poller/downloader.rb', line 5

def initialize(local_path)
  @local_path = local_path
end

Instance Method Details

#download(file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/s3poller/downloader.rb', line 9

def download(file)
  begin
    $log.info("Downloading: #{file.key}")
    local_file_path = "#{@local_path}#{file.key}"
    dirname = File.dirname(local_file_path)
    FileUtils.mkdir_p(dirname)
    File.open(local_file_path, 'w') do |local_file|
      local_file.write(file.body)
    end
  rescue Exception => e
    $log.error("Failed to download file #{file.key}, #{e.message}")
  end
end