Sha256: e3e8a57e80cb29b1134ecf453a229b544384c3e40fe6a5c3e81afec916d4f16d

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

require 'alephant/broker/component_meta'
require 'alephant/broker/errors/content_not_found'
require 'alephant/broker/error_component'
require 'alephant/logger'

module Alephant
  module Broker
    class ComponentFactory
      include Logger

      def initialize(load_strategy)
        @load_strategy = load_strategy
      end

      def create(id, batch_id, options)
        component_meta = ComponentMeta.new(id, batch_id, options)
        Component.new(
          component_meta,
          @load_strategy.load(component_meta)
        )
      rescue Alephant::Broker::Errors::ContentNotFound => e
        logger.warn 'Broker.ComponentFactory.create: Exception raised (ContentNotFound)'
        logger.metric(:name => "BrokerComponentFactoryContentNotFound", :unit => "Count", :value => 1)
        ErrorComponent.new(component_meta, 404, e)
      rescue => e
        logger.warn("Broker.ComponentFactory.create: Exception raised (#{e.message}, #{e.backtrace.join('\n')})")
        logger.metric(:name => "BrokerComponentFactoryExceptionRaised", :unit => "Count", :value => 1)
        ErrorComponent.new(component_meta, 500, e)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
alephant-broker-3.5.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.4.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.4.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.3.2 lib/alephant/broker/component_factory.rb
alephant-broker-3.3.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.3.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.2.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.1.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.1.0 lib/alephant/broker/component_factory.rb