Class: JobsAutoscaling::AwsAction
- Inherits:
-
Object
- Object
- JobsAutoscaling::AwsAction
- Defined in:
- lib/jobs_autoscaling/aws_action.rb
Constant Summary collapse
- 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.
'http://169.254.169.254/latest/meta-data/instance-id'
Instance Attribute Summary collapse
-
#asg_name ⇒ Object
readonly
Returns the value of attribute asg_name.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#busy ⇒ Object
it’s intentional that if this call fails, the error bubbles up to inst-jobs and errors the WorkQueue.
- #idle ⇒ Object
-
#initialize(asg_name:, aws_config: {}, instance_id: nil) ⇒ AwsAction
constructor
A new instance of AwsAction.
- #instance_id ⇒ Object
Constructor Details
#initialize(asg_name:, aws_config: {}, instance_id: nil) ⇒ AwsAction
Returns a new instance of AwsAction.
9 10 11 12 13 |
# 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 |
Instance Attribute Details
#asg_name ⇒ Object (readonly)
Returns the value of attribute asg_name.
7 8 9 |
# File 'lib/jobs_autoscaling/aws_action.rb', line 7 def asg_name @asg_name end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/jobs_autoscaling/aws_action.rb', line 7 def client @client end |
Instance Method Details
#busy ⇒ Object
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.
26 27 28 29 30 31 32 |
# 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 ⇒ Object
15 16 17 18 19 20 21 |
# 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 ⇒ Object
39 40 41 |
# File 'lib/jobs_autoscaling/aws_action.rb', line 39 def instance_id @instance_id ||= Net::HTTP.get(URI.parse(INSTANCE_ID_ENDPOINT)) end |