Class: Lono::Sets::Status::Instance::Base

Inherits:
Object
  • Object
show all
Includes:
AwsServices
Defined in:
lib/lono/sets/status/instance/base.rb

Direct Known Subclasses

Completed, Deleted, Show

Instance Method Summary collapse

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Helper

#rollback_complete?, #testing_update?

Methods included from AwsServices::StackSet

#find_stack_set, #stack_set_exists?

Methods included from AwsServices::Stack

#find_stack, #stack_exists?

Constructor Details

#initialize(stack_instance) ⇒ Base

Returns a new instance of Base.



51
52
53
54
55
# File 'lib/lono/sets/status/instance/base.rb', line 51

def initialize(stack_instance)
  @stack_instance = stack_instance
  @shown = []
  @output = "" # for say method and specs
end

Instance Method Details

#delayObject



110
111
112
113
114
115
116
117
118
# File 'lib/lono/sets/status/instance/base.rb', line 110

def delay
  # delay factor based on number of stack instances
  factor = self.class.delay_factor || 1
  base = 4.5
  delay = factor * base
  delay = [delay, 30].min # limit the delay to a max
  puts "Sleeping for #{delay}s..." if ENV['LONO_DEBUG_THROTTLE']
  sleep delay
end

#describe_stack_instanceObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/lono/sets/status/instance/base.rb', line 91

def describe_stack_instance
  retries = 0
  begin
    cfn.describe_stack_instance(
      stack_instance_account: @stack_instance.,
      stack_instance_region: @stack_instance.region,
      stack_set_name: @stack_instance.stack_set_id)
  rescue Aws::CloudFormation::Errors::Throttling => e
    retries += 1
    delay = 2 ** retries
    if ENV['LONO_DEBUG_THROTTLE']
      puts "#{e.class}: #{e.message}"
      puts "Backing off for #{delay}s and will retry"
    end
    sleep delay
    retry
  end
end

#say(text) ⇒ Object



87
88
89
# File 'lib/lono/sets/status/instance/base.rb', line 87

def say(text)
  ENV["LONO_TEST"] ? @output << "#{text}\n" : puts(text)
end

#show_instance(stack_instance) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lono/sets/status/instance/base.rb', line 57

def show_instance(stack_instance)
  already_shown = @shown.detect do |o|
    o[:account] == stack_instance[:account] &&
    o[:region] == stack_instance[:region] &&
    o[:status] == stack_instance[:status] &&
    o[:status_reason] == stack_instance[:status_reason]
  end
  return if already_shown

  s = stack_instance
  say status_line(s., s.region, s.status, s.status_reason)
end

#show_time_progressObject



70
71
72
# File 'lib/lono/sets/status/instance/base.rb', line 70

def show_time_progress
  self.class.show_time_progress
end

#status_line(account, region, status, reason = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/lono/sets/status/instance/base.rb', line 74

def status_line(, region, status, reason=nil)
  time = Time.now.strftime("%F %I:%M:%S%p") if show_time_progress
  items = [
    time,
    "Stack Instance:",
    "account".color(:purple), ,
    "region".color(:purple), region,
    "status".color(:purple), status,
  ]
  items += ["reason".color(:purple), reason] if reason
  items.compact.join(" ")
end