Class: CatalogItem::PriceUpdatedHandler

Inherits:
ApplicationJob
  • Object
show all
Includes:
RailsEventStore::AsyncHandler
Defined in:
app/subscribers/catalog_item/price_updated_handler.rb

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/subscribers/catalog_item/price_updated_handler.rb', line 7

def perform(event)
  data          = event.data
  price_was     = data[:price_was]
  price_now     = data[:price_now]
  return if price_was == price_now

  catalog_item = CatalogItem.find(data[:catalog_item_id])
  Rails.logger.info "CatalogItem::PriceUpdatedHandler: price change for #{data[:catalog_item_id]} from #{price_was} to #{price_now}"
  catalog_item.dependent_catalog_items.each(&:item_specs_or_price_updated)
  catalog_item.push_price_message
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end