Class: Collectors::ToS3
- Inherits:
-
Object
- Object
- Collectors::ToS3
- Defined in:
- lib/collectors/to_s3.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ ToS3
constructor
A new instance of ToS3.
- #push ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ ToS3
Returns a new instance of ToS3.
8 9 10 11 12 13 14 15 |
# File 'lib/collectors/to_s3.rb', line 8 def initialize(opts={}) @bucket_name = opts.fetch('<s3_bucket_name>') @task_name = opts.fetch('<as_task>', "file") @container_name = opts.fetch('<container_name>') @cmd = opts.fetch('<cmd>') @file_name = "#{`date '+#{@task_name}_%y-%m-%d_%H-%M'`.chop}.sql" end |
Instance Method Details
#push ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/collectors/to_s3.rb', line 17 def push DockerCompose::Client.new(container_name: @container_name, cmd: "#{@cmd} > #{@file_name}").exec file_name = Utils.compress(@file_name) s3 = S3::Client.new(file_name: file_name, bucket_name: @bucket_name) if s3.put(file_name) Utils.rm(file_name) puts "Pushed to S3." else puts "Unable to do the job." end end |