class Barbeque::HakoS3Client

Public Class Methods

new(oneshot_notification_prefix) click to toggle source

@param [String] oneshot_notification_prefix S3 location for oneshot notification

# 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

Public Instance Methods

get_stopped_result(hako_task) click to toggle source

@param [Barbeque::EcsHakoTask] hako_task @return [Aws::ECS::Types::Task, nil]

# 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() click to toggle source

@return [Aws::S3::Client]

# 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) click to toggle source

@param [Barbeque::EcsHakoTask] hako_task @return [String]

# 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