Class: Alephant::Broker::ComponentFactory

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/alephant/broker/component_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(load_strategy) ⇒ ComponentFactory

Returns a new instance of ComponentFactory.



11
12
13
# File 'lib/alephant/broker/component_factory.rb', line 11

def initialize(load_strategy)
  @load_strategy = load_strategy
end

Instance Method Details

#create(id, batch_id, options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/alephant/broker/component_factory.rb', line 15

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