Sha256: d6589f9ca7457e42b9c8f72ae06d8812b32135250dfe09e269e1ea0b6b1f1db2

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

require 'alephant/broker/errors'

module Alephant
  module Broker
    module LoadStrategy
      module Revalidate
        class Fetcher
          include Logger

          attr_reader :component_meta

          def initialize(component_meta)
            @component_meta = component_meta
          end

          def fetch
            Alephant::Broker::Cache::CachedObject.new(s3.get(s3_path))
          rescue AWS::S3::Errors::NoSuchKey, InvalidCacheKey => error
            logger.info(event: 'ErrorCaught', method: "#{self.class}#fetch", error: error)
            logger.metric('S3InvalidCacheKey')
            raise Alephant::Broker::Errors::ContentNotFound
          end

          private

          def s3_path
            lookup_read = lookup.read(component_meta.id, component_meta.options, 1)

            raise InvalidCacheKey if lookup_read.location.nil?

            lookup_read.location
          end

          def s3
            @s3 ||= Alephant::Storage.new(
              Broker.config[:s3_bucket_id],
              Broker.config[:s3_object_path]
            )
          end

          def lookup
            @lookup ||= Alephant::Lookup.create(
              Broker.config[:lookup_table_name],
              Broker.config
            )
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alephant-broker-3.16.2 lib/alephant/broker/load_strategy/revalidate/fetcher.rb
alephant-broker-3.16.1 lib/alephant/broker/load_strategy/revalidate/fetcher.rb
alephant-broker-3.16.0 lib/alephant/broker/load_strategy/revalidate/fetcher.rb
alephant-broker-3.15.2 lib/alephant/broker/load_strategy/revalidate/fetcher.rb
alephant-broker-3.15.1 lib/alephant/broker/load_strategy/revalidate/fetcher.rb
alephant-broker-3.15.0 lib/alephant/broker/load_strategy/revalidate/fetcher.rb