Class: JobWorkflow::AutoScaling::Adapter::AwsAdapter
- Inherits:
-
Object
- Object
- JobWorkflow::AutoScaling::Adapter::AwsAdapter
- Defined in:
- lib/job_workflow/auto_scaling/adapter/aws_adapter.rb,
sig/generated/job_workflow/auto_scaling/adapter/aws_adapter.rbs
Instance Attribute Summary collapse
- #cluster ⇒ String readonly
- #ecs_client ⇒ Aws::ECS::Client readonly
- #task_arn ⇒ String readonly
Instance Method Summary collapse
-
#describe_service ⇒ Aws::ECS::Types::Service
: () -> Aws::ECS::Types::Service.
-
#describe_service_name ⇒ String
: () -> String.
-
#initialize(ecs_client: nil) ⇒ AwsAdapter
constructor
: (?ecs_client: Aws::ECS::Client?) -> void.
-
#update_desired_count(desired_count) ⇒ Integer?
: (Integer) -> Integer?.
-
#update_service(service:, desired_count:) ⇒ Aws::ECS::Types::UpdateServiceResponse
: (service: Aws::ECS::Types::Service, desired_count: Integer) -> Aws::ECS::Types::UpdateServiceResponse.
Constructor Details
#initialize(ecs_client: nil) ⇒ AwsAdapter
: (?ecs_client: Aws::ECS::Client?) -> void
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? = JSON.parse(Net::HTTP.get(URI.parse("#{}/task"))) @ecs_client = ecs_client || Aws::ECS::Client.new @cluster = .fetch("Cluster") @task_arn = .fetch("TaskARN") end |
Instance Attribute Details
#cluster ⇒ String (readonly)
39 40 41 |
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 39 def cluster @cluster end |
#ecs_client ⇒ Aws::ECS::Client (readonly)
38 39 40 |
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 38 def ecs_client @ecs_client end |
#task_arn ⇒ String (readonly)
40 41 42 |
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 40 def task_arn @task_arn end |
Instance Method Details
#describe_service ⇒ Aws::ECS::Types::Service
: () -> Aws::ECS::Types::Service
51 52 53 54 55 |
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 51 def describe_service service_name = describe_service_name response = ecs_client.describe_services({ cluster: cluster, services: [service_name] }) response.services.first || (raise Error, "Service(#{service_name}) does not exist in cluster!") end |
#describe_service_name ⇒ String
: () -> String
43 44 45 46 47 48 |
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 43 def describe_service_name task = ecs_client.describe_tasks({ cluster: cluster, tasks: [task_arn] }).tasks.first raise Error, "Task(#{task_arn}) does not exist in cluster!" if task.nil? task.group.delete_prefix("service:") end |
#update_desired_count(desired_count) ⇒ Integer?
: (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 |
#update_service(service:, desired_count:) ⇒ Aws::ECS::Types::UpdateServiceResponse
: (service: Aws::ECS::Types::Service, desired_count: Integer) -> Aws::ECS::Types::UpdateServiceResponse
58 59 60 61 62 |
# File 'lib/job_workflow/auto_scaling/adapter/aws_adapter.rb', line 58 def update_service(service:, desired_count:) ecs_client.update_service( { cluster: service.cluster_arn, service: service.service_name, desired_count: desired_count } ) end |