Class: Rollo::Commands::Services

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

Overview

rubocop:disable Metrics/ClassLength

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rollo/commands/services.rb', line 12

def self.exit_on_failure?
  true
end

Instance Method Details

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

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/rollo/commands/services.rb', line 128

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

  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}"
        )
        # rubocop:disable Lint/ShadowingOuterLocalVariable
        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
        # rubocop:enable Lint/ShadowingOuterLocalVariable
      end
    end
  end
  say('Service instance counts decreased, continuing...')
end

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

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rollo/commands/services.rb', line 42

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 ||= Rollo::Model::ServiceCluster.new(ecs_cluster_name,
                                                       region)

  say("Increasing service instance counts by #{batch_size}...")
  # rubocop:disable Metrics/BlockLength
  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}"
        )
        # rubocop:disable Lint/ShadowingOuterLocalVariable
        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
        # rubocop:enable Lint/ShadowingOuterLocalVariable
      end
    end
  end
  # rubocop:enable Metrics/BlockLength
  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