class JobsAutoscaling::AwsAction
Constants
- INSTANCE_ID_ENDPOINT
This is the hard-coded EC2 endpoint for getting instance metadata. Oddly the ruby SDK doesn't include a method to get this information, you are expected to just hit the endpoint yourself.
Attributes
asg_name[R]
client[R]
Public Class Methods
new(asg_name:, aws_config: {}, instance_id: nil)
click to toggle source
# File lib/jobs_autoscaling/aws_action.rb, line 9 def initialize(asg_name:, aws_config: {}, instance_id: nil) @asg_name = asg_name @client = Aws::AutoScaling::Client.new(aws_config.reverse_merge(retry_limit: 10)) @instance_id = instance_id end
Public Instance Methods
busy()
click to toggle source
it's intentional that if this call fails, the error bubbles up to inst-jobs and errors the WorkQueue. We don't want to start running the job if we weren't able to block scaledowns.
# File lib/jobs_autoscaling/aws_action.rb, line 26 def busy @client.set_instance_protection( protected_from_scale_in: true, auto_scaling_group_name: asg_name, instance_ids: [instance_id], ) end
idle()
click to toggle source
# File lib/jobs_autoscaling/aws_action.rb, line 15 def idle @client.set_instance_protection( protected_from_scale_in: false, auto_scaling_group_name: asg_name, instance_ids: [instance_id], ) end
instance_id()
click to toggle source
# File lib/jobs_autoscaling/aws_action.rb, line 39 def instance_id @instance_id ||= Net::HTTP.get(URI.parse(INSTANCE_ID_ENDPOINT)) end