Class: S3log::Runner
- Inherits:
-
Object
- Object
- S3log::Runner
- Defined in:
- lib/s3log/runner.rb
Instance Method Summary collapse
- #buckets ⇒ Object
- #download ⇒ Object
-
#initialize(configfile) ⇒ Runner
constructor
A new instance of Runner.
- #items ⇒ Object
Constructor Details
#initialize(configfile) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/s3log/runner.rb', line 7 def initialize(configfile) @config = YAML::load_file(configfile) @s3 = AWS::S3.new( access_key_id: @config['awspublic'], secret_access_key: @config['awsprivate'] ) @bucket = @s3.buckets[@config['bucket']] @prefix = @config['prefix'] @logdir = @config['logdir'] FileUtils.mkdir(@logdir) unless Dir.exists? @logdir S3log::Log.set_logger(File.join(@logdir, 's3log.log'), @config['loglevel']) end |
Instance Method Details
#buckets ⇒ Object
24 25 26 27 28 |
# File 'lib/s3log/runner.rb', line 24 def buckets @s3.buckets.each do |bucket| puts bucket.name end end |
#download ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/s3log/runner.rb', line 30 def download if items.size > 0 time = Time.now S3log::Log.info "Downloading #{items.size} file." File.open(@config['outputfile'], 'a+') do |f| items.each do |i| f.puts @bucket.objects[i].read S3log::Log.debug " #{i} added." @bucket.objects[i].delete end end S3log::Log.info "... done in #{Time.now - time}s." else S3log::Log.debug "No file to download." end end |
#items ⇒ Object
20 21 22 |
# File 'lib/s3log/runner.rb', line 20 def items @_items ||= @bucket.objects.with_prefix(@prefix).collect(&:key) end |