Sha256: a36acdff4fde285ef5c8eed51872700b48fe736742d8856d482d7690fe5aa4e7

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Dynomite
  class Waiter
    include Client

    def wait(table_name)
      logger.info "Waiting for #{table_name} table to be ready."
      statuses = [:initial]
      until statuses.all? { |s| s == "ACTIVE" } do
        resp = client.describe_table(table_name: table_name)

        table = resp.table
        # table_status: CREATING UPDATING DELETING ACTIVE INACCESSIBLE_ENCRYPTION_CREDENTIALS ARCHIVING ARCHIVED
        table_status = table.table_status
        statuses = [table_status]
        # index_status: CREATING UPDATING DELETING ACTIVE
        indexes = table.global_secondary_indexes || []
        statuses += indexes.map { |i| i.index_status }
        print '.'
        sleep pause_time
      end
      puts
    end

    def wait_for_delete(table_name)
      logger.info "Waiting for #{table_name} table to be deleted."
      begin
        client.describe_table(table_name: table_name)
        print '.'
        sleep pause_time
      rescue Aws::DynamoDB::Errors::ResourceNotFoundException => e
      end
      puts
    end

  private
    def pause_time
      1
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dynomite-2.0.3 lib/dynomite/waiter.rb
dynomite-2.0.2 lib/dynomite/waiter.rb
dynomite-2.0.1 lib/dynomite/waiter.rb
dynomite-2.0.0 lib/dynomite/waiter.rb