Class: Ufo::Scale

Inherits:
Object
  • Object
show all
Includes:
AwsService, Default
Defined in:
lib/ufo/scale.rb

Instance Method Summary collapse

Methods included from AwsService

#cloudwatchlogs, #ecr, #ecs, #elb

Methods included from Default

#default_cluster, #default_desired_count, #default_maximum_percent, #default_minimum_healthy_percent, #new_service_setting, #setting

Constructor Details

#initialize(service, count, options = {}) ⇒ Scale

Returns a new instance of Scale.



6
7
8
9
10
11
# File 'lib/ufo/scale.rb', line 6

def initialize(service, count, options={})
  @service = service
  @count = count
  @options = options
  @cluster = @options[:cluster] || default_cluster
end

Instance Method Details

#service_exists?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/ufo/scale.rb', line 27

def service_exists?
  cluster = ecs.describe_clusters(clusters: [@cluster]).clusters.first
  return false unless cluster
  service = ecs.describe_services(services: [@service], cluster: @cluster).services.first
  !!service
end

#updateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ufo/scale.rb', line 13

def update
  unless service_exists?
    puts "Unable to find the #{@service} service on #{@cluster} cluster."
    puts "Are you sure you are trying to scale the right service on the right cluster?"
    exit
  end
  ecs.update_service(
    service: @service,
    cluster: @cluster,
    desired_count: @count
  )
  puts "Scale #{@service} service in #{@cluster} cluster to #{@count}" unless @options[:mute]
end