Class: Puma::Redeploy::S3Handler

Inherits:
BaseHandler show all
Defined in:
lib/puma/redeploy/s3_handler.rb

Overview

S3 based redeploy handler

Instance Attribute Summary collapse

Attributes inherited from BaseHandler

#watch_file

Instance Method Summary collapse

Methods inherited from BaseHandler

#needs_redeploy?, #watch_file_data

Constructor Details

#initialize(watch_file:, deployer:, logger:, s3_client:) ⇒ S3Handler

Returns a new instance of S3Handler.



12
13
14
15
16
17
# File 'lib/puma/redeploy/s3_handler.rb', line 12

def initialize(watch_file:, deployer:, logger:, s3_client:)
  super(watch_file:, deployer:, logger:)
  @s3_client = s3_client
  @bucket_name, @object_key = s3_object_reference(watch_file)
  @touched_at = touched_at
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



10
11
12
# File 'lib/puma/redeploy/s3_handler.rb', line 10

def bucket_name
  @bucket_name
end

#object_keyObject (readonly)

Returns the value of attribute object_key.



10
11
12
# File 'lib/puma/redeploy/s3_handler.rb', line 10

def object_key
  @object_key
end

#s3_clientObject (readonly)

Returns the value of attribute s3_client.



10
11
12
# File 'lib/puma/redeploy/s3_handler.rb', line 10

def s3_client
  @s3_client
end

Instance Method Details

#archive_file(archive_location) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puma/redeploy/s3_handler.rb', line 19

def archive_file(archive_location)
  return unless archive_location

  archive_bucket_name, archive_object_key = s3_object_reference(archive_location)

  response = s3_client.get_object(bucket: archive_bucket_name, key: archive_object_key)

  file_name = local_file_path(archive_object_key)
  # Write the object data to a local file
  File.binwrite(file_name, response.body.read)
  file_name
rescue StandardError => e
  logger.warn "Error reading fetching archive file for #{archive_location}. Error:#{e.message}"
end