Sha256: 28f7d065c8ddef573547e15002471980ff035d372759e366cb0c2ada24b65d1d

Contents?: true

Size: 1.04 KB

Versions: 17

Compression:

Stored size: 1.04 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) for #{component_meta.component_key}"
        logger.metric "ContentNotFound"
        ErrorComponent.new(component_meta, 404, e)
      rescue => e
        logger.warn "Broker.ComponentFactory.create: Exception raised (#{e.message}, #{e.backtrace.join('\n')})"
        logger.metric "ExceptionRaised"
        ErrorComponent.new(component_meta, 500, e)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
alephant-broker-3.13.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.12.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.11.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.10.2 lib/alephant/broker/component_factory.rb
alephant-broker-3.10.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.10.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.9.2 lib/alephant/broker/component_factory.rb
alephant-broker-3.9.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.9.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.8.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.7.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.7.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.6.1 lib/alephant/broker/component_factory.rb
alephant-broker-3.6.0 lib/alephant/broker/component_factory.rb
alephant-broker-3.5.5 lib/alephant/broker/component_factory.rb
alephant-broker-3.5.4 lib/alephant/broker/component_factory.rb
alephant-broker-3.5.3 lib/alephant/broker/component_factory.rb