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
30
31
32
33
34
35
36
37
# 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.error(
    method: 'Broker.ComponentFactory.create',
    message: 'Exception raised (ContentNotFound)',
    component_key: component_meta.component_key
  )
  logger.metric "ContentNotFound"
  ErrorComponent.new(component_meta, 404, e)
rescue => e
  logger.error(
    method:    'Broker.ComponentFactory.create',
    message:   e.message,
    backtrace: e.backtrace.join('\n')
  )
  logger.metric "ExceptionRaised"
  ErrorComponent.new(component_meta, 500, e)
end