class Alephant::Lookup::LookupQuery

Attributes

lookup_location[R]
table_name[R]

Public Class Methods

new(table_name, component_id, opts, batch_version) click to toggle source
# File lib/alephant/lookup/lookup_query.rb, line 11
def initialize(table_name, component_id, opts, batch_version)
  options = {}
  options[:endpoint] = ENV['AWS_DYNAMO_DB_ENDPOINT'] if ENV['AWS_DYNAMO_DB_ENDPOINT']
  @client            = Aws::DynamoDB::Client.new(options)
  @table_name        = table_name
  @lookup_location   = LookupLocation.new(component_id, opts, batch_version)

  logger.info(
    "event"        => "LookupQueryInitialized",
    "tableName"    => table_name,
    "componentId"  => component_id,
    "location"     => lookup_location,
    "batchVersion" => batch_version,
    "method"       => "#{self.class}#initialize"
  )
end

Public Instance Methods

run!() click to toggle source
# File lib/alephant/lookup/lookup_query.rb, line 28
def run!
  lookup_location.tap do |l|
    l.location = s3_location_from(
      @client.query(to_q)
    ).tap do |loc|
      logger.info(
        "event"    => "S3LocationRetrieved",
        "location" => loc,
        "method"   => "#{self.class}#run!"
      )
    end
  end
end

Private Instance Methods

s3_location_from(result) click to toggle source
# File lib/alephant/lookup/lookup_query.rb, line 44
def s3_location_from(result)
  result.count == 1 ? result.items.first['location'] : nil
end
to_q() click to toggle source
# File lib/alephant/lookup/lookup_query.rb, line 48
def to_q
  {
    :table_name => table_name,
    :consistent_read => true,
    :projection_expression => '#loc',
    :expression_attribute_names => {
      '#loc' => 'location'
    },
    :key_condition_expression => 'component_key = :component_key AND batch_version = :batch_version',
    :expression_attribute_values => {
      ':component_key' => @lookup_location.component_key,
      ':batch_version' => @lookup_location.batch_version.to_i # @TODO: Verify if this is nil as this would be 0
    }
  }
end