Class: Aws::SiteMonitor::Site
- Inherits:
-
Object
- Object
- Aws::SiteMonitor::Site
show all
- Includes:
- PstoreRecord
- Defined in:
- lib/aws/site_monitor/site.rb
Instance Method Summary
collapse
#[], #[]=, #attributes, #destroy, #save
Constructor Details
#initialize(**options) ⇒ Site
Returns a new instance of Site.
6
7
8
9
|
# File 'lib/aws/site_monitor/site.rb', line 6
def initialize(**options)
super(**options)
@failure_count ||= 0
end
|
Instance Method Details
#handle_failure!(options) ⇒ Object
this handles issues where instance cannot be restarted due to normal reboot. since hard stopping takes longer, we don’t want to do it unless necessary. the reset failure count is semi wonky because it will reset even if success hasnt yet been reached, however it is much less complicated than trying to query state of multiple instances. basically if threshold is reached, hard stop the instances, then on next pass since we reset the failure count, it should attempt normal reboot, which will cause the instances to start
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/aws/site_monitor/site.rb', line 18
def handle_failure!(options)
hard_stop_enabled = options.attempts_until_hard_stop > 0
if hard_stop_enabled && self[:failure_count] == options.attempts_until_hard_stop
reset_failure_count
stop_instances!
else
reboot_instances!
end
end
|
#reboot_instances! ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/aws/site_monitor/site.rb', line 39
def reboot_instances!
puts "RESTARTING SITE #{self.attributes}"
::Aws::SiteMonitor.ec2_client.reboot_instances(
instance_ids: self[:instance_ids]
)
rescue ::Aws::EC2::Errors::IncorrectState => e
puts e.message
start_instances!
end
|
#reset_failure_count ⇒ Object
34
35
36
37
|
# File 'lib/aws/site_monitor/site.rb', line 34
def reset_failure_count
@failure_count = 0
save
end
|
#start_instances! ⇒ Object
49
50
51
52
53
54
|
# File 'lib/aws/site_monitor/site.rb', line 49
def start_instances!
puts "STARTING STOPPED INSTANCES"
::Aws::SiteMonitor.ec2_client.start_instances(
instance_ids: self[:instance_ids]
)
end
|
#stop_instances! ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/aws/site_monitor/site.rb', line 56
def stop_instances!
::Aws::SiteMonitor.ec2_client.stop_instances(
instance_ids: self[:instance_ids]
)
rescue ::Aws::EC2::Errors::IncorrectState => e
start_instances!
end
|
#track_failure ⇒ Object
29
30
31
32
|
# File 'lib/aws/site_monitor/site.rb', line 29
def track_failure
@failure_count = @failure_count + 1
save
end
|