Class: JobsAutoscaling::AwsAction

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_nameObject (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

#clientObject (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

#busyObject

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

#idleObject



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_idObject



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