Class: Barbeque::HakoS3Client

Inherits:
Object
  • Object
show all
Defined in:
lib/barbeque/hako_s3_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(oneshot_notification_prefix) ⇒ HakoS3Client

Returns a new instance of HakoS3Client.

Parameters:

  • oneshot_notification_prefix (String)

    S3 location for oneshot notification



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?

Parameters:

Returns:

  • (Aws::ECS::Types::Task, nil)


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_clientAws::S3::Client

Returns:

  • (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

Parameters:

Returns:

  • (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