Sha256: 42c80535f51c122bb6275d3de7239e6c02d7ec9768e1aafe86560c657ed54a2d

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

require "aws-sdk-dynamodb"
require "thread"
require "timeout"

require "alephant/support/dynamodb/table"
require "alephant/logger"

module Alephant
  module Lookup
    class LookupTable < ::Alephant::Support::DynamoDB::Table
      include Logger
      attr_reader :table_name, :client

      def initialize(table_name)
        options = {}
        options.merge!({endpoint: ENV['AWS_DYNAMO_DB_ENDPOINT']}) if ENV['AWS_DYNAMO_DB_ENDPOINT']
        @mutex      = Mutex.new
        @client     = Aws::DynamoDB::Client.new(options)
        @table_name = table_name
        logger.info(
          "event"     => "LookupTableInitialized",
          "tableName" => table_name,
          "method"    => "#{self.class}#initialize"
        )
      end

      def write(component_key, version, location)
        client.put_item({
          table_name: table_name,
          item: {
            'component_key' => component_key.to_s,
            'batch_version' => version,
            'location'      => location.to_s
          }
        }).tap do
          logger.info(
            "event"        => "LookupLocationWritten",
            "componentKey" => component_key,
            "version"      => version,
            "location"     => location,
            "method"       => "#{self.class}#write"
          )
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alephant-lookup-2.2.0 lib/alephant/lookup/lookup_table.rb
alephant-lookup-2.1.0 lib/alephant/lookup/lookup_table.rb