Class: Barbeque::HakoS3Client
- Inherits:
-
Object
- Object
- Barbeque::HakoS3Client
- Defined in:
- lib/barbeque/hako_s3_client.rb
Instance Method Summary collapse
- #get_stopped_result(hako_task) ⇒ Aws::ECS::Types::Task?
-
#initialize(oneshot_notification_prefix) ⇒ HakoS3Client
constructor
A new instance of HakoS3Client.
- #s3_client ⇒ Aws::S3::Client
- #s3_key_for_stopped_result(hako_task) ⇒ String
Constructor Details
#initialize(oneshot_notification_prefix) ⇒ HakoS3Client
Returns a new instance of HakoS3Client.
8 9 10 11 12 13 |
# File 'lib/barbeque/hako_s3_client.rb', line 8 def initialize(oneshot_notification_prefix) uri = URI.parse(oneshot_notification_prefix) @s3_bucket = uri.host @s3_prefix = uri.path.sub(%r{\A/}, '') @s3_region = URI.decode_www_form(uri.query || '').to_h['region'] end |
Instance Method Details
#get_stopped_result(hako_task) ⇒ Aws::ECS::Types::Task?
28 29 30 31 32 33 34 35 |
# File 'lib/barbeque/hako_s3_client.rb', line 28 def get_stopped_result(hako_task) object = s3_client.get_object(bucket: @s3_bucket, key: s3_key_for_stopped_result(hako_task)) result = JSON.parse(object.body.read) detail = result.fetch('detail') Aws::Json::Parser.new(Aws::ECS::Client.api.operation('describe_tasks').output.shape.member(:tasks).shape.member).parse(JSON.dump(detail)) rescue Aws::S3::Errors::NoSuchKey nil end |
#s3_client ⇒ Aws::S3::Client
22 23 24 |
# File 'lib/barbeque/hako_s3_client.rb', line 22 def s3_client @s3_client ||= Aws::S3::Client.new(region: @s3_region, http_read_timeout: 5) end |
#s3_key_for_stopped_result(hako_task) ⇒ String
17 18 19 |
# File 'lib/barbeque/hako_s3_client.rb', line 17 def s3_key_for_stopped_result(hako_task) "#{@s3_prefix}/#{hako_task.task_arn}/stopped.json" end |