Class: DbBlaster::S3Publisher

Inherits:
BasePublisher show all
Defined in:
lib/db_blaster/s3_publisher.rb

Overview

Pushes records to S3

Instance Attribute Summary

Attributes inherited from BasePublisher

#batch_start_time, #records, #source_table

Instance Method Summary collapse

Methods inherited from BasePublisher

#initialize, publish

Constructor Details

This class inherits a constructor from DbBlaster::BasePublisher

Instance Method Details

#clientObject



40
41
42
43
44
# File 'lib/db_blaster/s3_publisher.rb', line 40

def client
  @client ||= Aws::S3::Client.new(region: DbBlaster.configuration.aws_region,
                                  credentials: Aws::Credentials.new(DbBlaster.configuration.aws_access_key,
                                                                    DbBlaster.configuration.aws_access_secret))
end

#contentObject



16
17
18
19
20
21
# File 'lib/db_blaster/s3_publisher.rb', line 16

def content
  return meta_records if DbBlaster.configuration.s3_meta_format == Configuration::INLINE_S3_META_FORMAT

  { meta: meta,
    records: records }
end

#metaObject



32
33
34
# File 'lib/db_blaster/s3_publisher.rb', line 32

def meta
  @meta ||= (DbBlaster.configuration.s3_meta.presence || {}).merge(source_table: source_table.name)
end

#meta_recordsObject



36
37
38
# File 'lib/db_blaster/s3_publisher.rb', line 36

def meta_records
  records.collect { |record| record.merge(meta) }
end

#publishObject



8
9
10
11
12
13
14
# File 'lib/db_blaster/s3_publisher.rb', line 8

def publish
  client.put_object(bucket: DbBlaster.configuration.s3_bucket,
                    key: S3KeyBuilder.build(source_table_name: source_table.name,
                                            batch_start_time: batch_start_time),
                    tagging: tagging,
                    body: content.to_json)
end

#taggingObject



23
24
25
# File 'lib/db_blaster/s3_publisher.rb', line 23

def tagging
  URI.encode_www_form(tags_hash)
end

#tags_hashObject



27
28
29
30
# File 'lib/db_blaster/s3_publisher.rb', line 27

def tags_hash
  @tags_hash ||= { source_table: source_table.name }
                 .merge(DbBlaster.configuration.s3_tags.presence || {})
end