Class: Terastream::Output::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/terastream/middleware/output/s3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ S3

Returns a new instance of S3.



9
10
11
12
13
14
# File 'lib/terastream/middleware/output/s3.rb', line 9

def initialize(options = {})
  @options = options
  @temp = ""
  @connection = Aws::S3::Client.new(region: region)
  @records = []
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/terastream/middleware/output/s3.rb', line 7

def options
  @options
end

Instance Method Details

#<<(record) ⇒ Object



16
17
18
# File 'lib/terastream/middleware/output/s3.rb', line 16

def <<(record)
  @temp += record.is_a?(Hash) || record.is_a?(String) ? as_json(record) : as_csv(record)
end

#complete!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/terastream/middleware/output/s3.rb', line 20

def complete!
  tries = @max_retries
  begin
    @connection.put_object(
      key: options[:key],
      bucket: options[:bucket],
      body: @temp
    )
  rescue => e
    retries -= 1
    retry if tries > 0
  end
end