Class: JobWorkflow::AutoScaling::Adapter::AwsAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/auto_scaling/adapter/aws_adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(ecs_client: nil) ⇒ AwsAdapter

: (?ecs_client: Aws::ECS::Client?) -> void

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 12

def initialize(ecs_client: nil)
  unless defined?(Aws::ECS::Client)
    raise Error, "aws-sdk-ecs is required for JobWorkflow::AutoScaling::Adapter::AwsAdapter"
  end

   = ENV.fetch("ECS_CONTAINER_METADATA_URI_V4", nil)
  raise Error, "ECS_CONTAINER_METADATA_URI_V4 is required on ECS" if .nil?

  task_meta = JSON.parse(Net::HTTP.get(URI.parse("#{}/task")))

  @ecs_client = ecs_client || Aws::ECS::Client.new
  @cluster = task_meta.fetch("Cluster")
  @task_arn = task_meta.fetch("TaskARN")
end

Instance Method Details

#update_desired_count(desired_count) ⇒ Object

: (Integer) -> Integer?



28
29
30
31
32
33
34
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 28

def update_desired_count(desired_count)
  service = describe_service
  return if service.desired_count == desired_count

  update_service(service: service, desired_count: desired_count)
  desired_count
end