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



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

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



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

def current_scale
  scale_string_to_hash fc_scale
end

#defined_scaleObject



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

def defined_scale
  scale_string_to_hash ENV[defined_scale_key].to_s
end

#defined_scale_keyObject



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

def defined_scale_key
  "FLYNN_#{ current_branch }_SCALE"
end

#fc_scale(scale_options_to_set = nil) ⇒ Object



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

def fc_scale(scale_options_to_set = nil)
  run_command "flynn scale#{ " #{ scale_options_to_set }" unless scale_options_to_set.nil? || scale_options_to_set.empty? }".chomp
end

#scale_options_to_setObject



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

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.join(' ')
end

#scale_string_to_hash(scale_string) ⇒ Object



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

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