Sha256: ac4fe5fe85971f968297e997656c55852d095ae80b882cff6cc696ebe38d3641

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

Contents

module Backupsss
  # A class for delivering a tar to S3
  class Backup
    attr_reader :config, :client, :filename

    def initialize(config, client)
      @config       = config
      @client       = client
      @filename = config[:filename]
    end

    def put_file(file)
      client.put_object(bucket_opts.merge(body: file))
      wait_for_object
    end

    private

    def wait_for_object
      client.wait_until(:object_exists, bucket_opts) do |w|
        w.before_attempt { |n| display_checked_count_message(n) }
        w.before_wait    { |_, resp| display_before_wait_message(resp) }
      end
    end

    def display_checked_count_message(count)
      puts "Checked S3 #{count} times"
    end

    def display_before_wait_message(resp)
      puts "Client got: #{resp}\nwaiting before trying again"
    end

    def bucket_opts
      {
        bucket: config[:s3_bucket],
        key:    "#{config[:s3_bucket_prefix]}/#{filename}"
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
backupsss-0.1.0 lib/backupsss/backup.rb