Module: Satorix::CI::Deploy::Flynn::Scale

Included in:
Satorix::CI::Deploy::Flynn
Defined in:
lib/satorix/CI/deploy/flynn/scale.rb

Instance Method Summary collapse

Instance Method Details

#adjust_scaleObject



7
8
9
10
11
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 7

def adjust_scale
  cached_scale_options_to_set = scale_options_to_set
  log "No scale specified in #{ defined_scale_key }. Displaying current scale:" if cached_scale_options_to_set.empty?
  fc_scale cached_scale_options_to_set
end

#current_scaleObject



14
15
16
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 14

def current_scale
  scale_string_to_hash fc_scale
end

#defined_scaleObject



19
20
21
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 19

def defined_scale
  scale_string_to_hash ENV[defined_scale_key].to_s
end

#defined_scale_keyObject



24
25
26
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 24

def defined_scale_key
  "FLYNN_#{ current_branch }_SCALE"
end

#fc_scale(scale_options_to_set = []) ⇒ Object



29
30
31
32
33
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 29

def fc_scale(scale_options_to_set = [])
  command = %w[flynn scale].concat(scale_options_to_set)

  run_command(command)
end

#scale_options_to_setObject



36
37
38
39
40
41
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 36

def scale_options_to_set
  [].tap do |scale|
    defined_scale.each { |job, workers| scale << "#{ job }=#{ workers }" }
    (current_scale.keys - defined_scale.keys).each { |job| scale << "#{ job }=0" } unless defined_scale.empty?
  end
end

#scale_string_to_hash(scale_string) ⇒ Object



44
45
46
# File 'lib/satorix/CI/deploy/flynn/scale.rb', line 44

def scale_string_to_hash(scale_string)
  {}.tap { |jobs| scale_string.split.map { |x| x.partition('=') }.each { |x| jobs[x.first.to_sym] = x.last } }
end