Class: AwsHelpers::RDS::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_helpers/rds/instance.rb

Instance Method Summary collapse

Constructor Details

#initialize(rds_client, db_instance_id) ⇒ Instance

Returns a new instance of Instance


16
17
18
19
# File 'lib/aws_helpers/rds/instance.rb', line 16

def initialize(rds_client, db_instance_id)
  @rds_client = rds_client
  @db_instance_id = db_instance_id
end

Instance Method Details

#poll_availableObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/aws_helpers/rds/instance.rb', line 21

def poll_available

  loop do

    instance = @rds_client.describe_db_instances(db_instance_identifier: @db_instance_id)[:db_instances].first
    state = instance[:db_instance_status]
    puts "RDS - #{@db_instance_id} is #{state}"

    case state
      when InstanceState::AVAILABLE
        break
      when InstanceState::BACKING_UP, InstanceState::MODIFYING, InstanceState::REBOOTING
        sleep 30
      else
        raise "RDS - #{@db_instance_id} will never become #{InstanceState::AVAILABLE}"
    end

  end

end