Sha256: ad6b812028455b7798796108d31d398181e511f994f4f74214711cf7df9f24f3

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

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

      private

      def opts
        {
          :dimensions => {
            :module   => "AlephantBroker",
            :class    => "ComponentFactory",
            :function => "create"
          }
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-broker-3.5.1 lib/alephant/broker/component_factory.rb