Module: MovableInk::AWS::Autoscaling
- Included in:
- MovableInk::AWS
- Defined in:
- lib/movable_ink/aws/autoscaling.rb
Instance Method Summary collapse
- #autoscaling(region: my_region) ⇒ Object
- #complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) ⇒ Object
- #delete_role_tag(role:) ⇒ Object
- #keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) ⇒ Object
- #mark_me_as_healthy(role:) ⇒ Object
- #mark_me_as_unhealthy ⇒ Object
- #record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) ⇒ Object
Instance Method Details
#autoscaling(region: my_region) ⇒ Object
6 7 8 9 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 6 def autoscaling(region: my_region) @autoscaling_client ||= {} @autoscaling_client[region] ||= Aws::AutoScaling::Client.new(region: region) end |
#complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 49 def complete_lifecycle_action(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) raise ArgumentError.new('lifecycle_action_token or instance_id required') if lifecycle_action_token.nil? && instance_id.nil? if lifecycle_action_token run_with_backoff do autoscaling.complete_lifecycle_action({ lifecycle_hook_name: lifecycle_hook_name, auto_scaling_group_name: auto_scaling_group_name, lifecycle_action_token: lifecycle_action_token, lifecycle_action_result: 'CONTINUE' }) end else run_with_backoff do autoscaling.complete_lifecycle_action({ instance_id: instance_id, lifecycle_hook_name: lifecycle_hook_name, auto_scaling_group_name: auto_scaling_group_name, lifecycle_action_result: 'CONTINUE' }) end end end |
#delete_role_tag(role:) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 35 def delete_role_tag(role:) run_with_backoff do ec2.({ resources: [instance_id], tags: [ { key: "mi:roles", value: role } ] }) end end |
#keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 95 def keep_instance_alive(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) 24.downto(1) do |hours| record_lifecycle_action_heartbeat( lifecycle_hook_name: lifecycle_hook_name, auto_scaling_group_name: auto_scaling_group_name, lifecycle_action_token: lifecycle_action_token, instance_id: instance_id ) sleep 3600 end end |
#mark_me_as_healthy(role:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 21 def mark_me_as_healthy(role:) run_with_backoff do ec2.({ resources: [instance_id], tags: [ { key: "mi:roles", value: role } ] }) end end |
#mark_me_as_unhealthy ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 11 def mark_me_as_unhealthy run_with_backoff do autoscaling.set_instance_health({ health_status: "Unhealthy", instance_id: instance_id, should_respect_grace_period: false }) end end |
#record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/movable_ink/aws/autoscaling.rb', line 73 def record_lifecycle_action_heartbeat(lifecycle_hook_name:, auto_scaling_group_name:, lifecycle_action_token: nil, instance_id: nil) raise ArgumentError.new('lifecycle_action_token or instance_id required') if lifecycle_action_token.nil? && instance_id.nil? if lifecycle_action_token run_with_backoff do autoscaling.record_lifecycle_action_heartbeat({ lifecycle_hook_name: lifecycle_hook_name, auto_scaling_group_name: auto_scaling_group_name, lifecycle_action_token: lifecycle_action_token }) end else run_with_backoff do autoscaling.record_lifecycle_action_heartbeat({ instance_id: instance_id, lifecycle_hook_name: lifecycle_hook_name, auto_scaling_group_name: auto_scaling_group_name, }) end end end |