class S3Poller::Poller

Public Class Methods

new(config_path, local_path) click to toggle source
# File lib/s3poller/poller.rb, line 8
def initialize(config_path, local_path)
  @local_path = local_path
  @aws_config = YAML::load(File.open(config_path))
end

Public Instance Methods

poll() click to toggle source
# File lib/s3poller/poller.rb, line 13
def poll
  begin
    files_to_download.each do |file| 
      downloader.download(file)
    end
  rescue Exception => e
    $log.error("Failed to poll #{e.message}")
  end
end

Private Instance Methods

bucket() click to toggle source
# File lib/s3poller/poller.rb, line 47
def bucket
  connection.directories.get(@aws_config[:bucket])
end
connection() click to toggle source
# File lib/s3poller/poller.rb, line 51
def connection
  @connection ||= Fog::Storage.new(@aws_config[:fog])
end
downloader() click to toggle source
# File lib/s3poller/poller.rb, line 43
def downloader
  @downloader ||= Downloader.new(@local_path)
end
files() click to toggle source
# File lib/s3poller/poller.rb, line 31
def files
  bucket.files.inject([]) {|files, file| files << file; files}
end
files_to_download() click to toggle source
# File lib/s3poller/poller.rb, line 25
def files_to_download
  files.select do |file|
    should_download?(file)
  end
end
should_download?(file) click to toggle source
# File lib/s3poller/poller.rb, line 35
def should_download?(file)
  local_filename = "#{@local_path}#{file.key}"
  return false if local_filename =~ /\/$/
  return false if File.directory?(local_filename)
  return true unless File.exist?(local_filename)
  S3Etag.calc(:file => local_filename) != file.etag
end