Class: Dynamoid::AdapterPlugin::AwsSdkV3::UntilPastTableStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, table_name, status = :creating) ⇒ UntilPastTableStatus

Returns a new instance of UntilPastTableStatus.


10
11
12
13
14
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb', line 10

def initialize(client, table_name, status = :creating)
  @client = client
  @table_name = table_name
  @status = status
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client


8
9
10
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb', line 8

def client
  @client
end

#statusObject (readonly)

Returns the value of attribute status


8
9
10
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb', line 8

def status
  @status
end

#table_nameObject (readonly)

Returns the value of attribute table_name


8
9
10
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb', line 8

def table_name
  @table_name
end

Instance Method Details

#callObject


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb', line 16

def call
  counter = 0
  resp = nil
  begin
    check = { again: true }
    while check[:again]
      sleep Dynamoid::Config.sync_retry_wait_seconds
      resp = client.describe_table(table_name: table_name)
      check = check_table_status?(counter, resp, status)
      Dynamoid.logger.info "Checked table status for #{table_name} (check #{check.inspect})"
      counter += 1
    end
  # If you issue a DescribeTable request immediately after a CreateTable
  #   request, DynamoDB might return a ResourceNotFoundException.
  # This is because DescribeTable uses an eventually consistent query,
  #   and the metadata for your table might not be available at that moment.
  # Wait for a few seconds, and then try the DescribeTable request again.
  # See: http://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#describe_table-instance_method
  rescue Aws::DynamoDB::Errors::ResourceNotFoundException => e
    case status
    when :creating
      if counter >= Dynamoid::Config.sync_retry_max_times
        Dynamoid.logger.warn "Waiting on table metadata for #{table_name} (check #{counter})"
        retry # start over at first line of begin, does not reset counter
      else
        Dynamoid.logger.error "Exhausted max retries (Dynamoid::Config.sync_retry_max_times) waiting on table metadata for #{table_name} (check #{counter})"
        raise e
      end
    else
      # When deleting a table, "not found" is the goal.
      Dynamoid.logger.info "Checked table status for #{table_name}: Not Found (check #{check.inspect})"
    end
  end
end