Class: Legion::CLI::Failover

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/failover_command.rb

Instance Method Summary collapse

Instance Method Details

#promoteObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/legion/cli/failover_command.rb', line 19

def promote
  out = formatter
  ensure_settings

  target = options[:region]
  require 'legion/region/failover'

  if options[:dry_run]
    run_dry_run(out, target)
  else
    run_promote(out, target)
  end
rescue Legion::Region::Failover::UnknownRegionError => e
  out.error(e.message)
  raise SystemExit, 1
rescue Legion::Region::Failover::LagTooHighError => e
  if options[:force]
    out.warn("#{e.message} — forcing promotion")
    force_promote(out, target)
  else
    out.error("#{e.message}. Use --force to override.")
    raise SystemExit, 1
  end
end

#statusObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/legion/cli/failover_command.rb', line 45

def status
  out = formatter
  ensure_settings

  region_config = Legion::Settings[:region] || {}
  if options[:json]
    out.json(region_config)
  else
    out.header('Region Configuration')
    out.detail({
                 current:          region_config[:current] || '(not set)',
                 primary:          region_config[:primary] || '(not set)',
                 failover:         region_config[:failover] || '(not set)',
                 peers:            (region_config[:peers] || []).join(', ').then { |s| s.empty? ? '(none)' : s },
                 default_affinity: region_config[:default_affinity] || 'prefer_local'
               })
  end
end