Class: Rollo::Commands::Services

Inherits:
Thor
  • Object
show all
Defined in:
lib/rollo/commands/services.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/rollo/commands/services.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#contract(region, _, ecs_cluster_name, service_cluster = nil) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rollo/commands/services.rb', line 102

def contract(
    region, _, ecs_cluster_name,
        service_cluster = nil)
  batch_size = options[:batch_size]

  service_cluster = service_cluster ||
      Rollo::Model::ServiceCluster.new(ecs_cluster_name, region)

  say("Decreasing service instance counts by #{batch_size}...")
  with_padding do
    service_cluster.with_replica_services do |on|
      on.each_service do |service|
        say(
            "Decreasing instance count by #{batch_size} " +
                "for #{service.name}")
        with_padding do
          service.decrease_instance_count_by(batch_size) do |on|
            on.prepare do |current, target|
              say(
                  "Changing instance count from #{current} " +
                      "to #{target}...")
            end
            on.waiting_for_health do |attempt|
              say(
                  'Waiting for service to reach a steady state ' +
                      "(attempt #{attempt})...")
            end
          end
        end
      end
    end
  end
  say("Service instance counts decreased, continuing...")
end

#expand(region, _, ecs_cluster_name, service_cluster = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rollo/commands/services.rb', line 34

def expand(
    region, _, ecs_cluster_name,
        service_cluster = nil)
  batch_size = options[:batch_size]
  maximum_instances = options[:maximum_instances]
  service_start_wait_minutes = options[:startup_time]
  service_start_wait_seconds = 60 * service_start_wait_minutes

  service_cluster = service_cluster ||
      Rollo::Model::ServiceCluster.new(ecs_cluster_name, region)

  say("Increasing service instance counts by #{batch_size}...")
  with_padding do
    service_cluster.with_replica_services do |on|
      on.start do |services|
        say(
            'Service cluster contains services:' +
                "\n\t\t[#{services.map(&:name).join(",\n\t\t ")}]")
      end
      on.each_service do |service|
        say(
            "Increasing instance count by #{batch_size} " +
                "for #{service.name}")
        with_padding do
          service.increase_instance_count_by(
              batch_size, maximum_instances: maximum_instances) do |on|
            on.prepare do |current, target|
              say(
                  "Changing instance count from #{current} " +
                      "to #{target}...")
            end
            on.waiting_for_health do |attempt|
              say(
                  "Waiting for service to reach a steady state " +
                      "(attempt #{attempt})...")
            end
          end
        end
      end
    end
  end
  say(
      "Waiting #{service_start_wait_minutes} minute(s) for " +
          'services to finish starting...')
  with_padding do
    sleep(service_start_wait_seconds)
    say(
        "Waited #{service_start_wait_minutes} minute(s). " +
            'Continuing...')
  end
  say('Service instance counts increased, continuing...')
end