Class: Workarea::UpdateProductReviewData

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::CallbacksWorker, Sidekiq::Worker
Defined in:
app/workers/workarea/update_product_review_data.rb

Instance Method Summary collapse

Instance Method Details

#perform(product_id) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'app/workers/workarea/update_product_review_data.rb', line 14

def perform(product_id)
  product = Workarea::Catalog::Product.find(product_id)
  review_data = Review.find_single_aggregates(product_id)

  product.update_attributes!(
    total_reviews: review_data[:count],
    average_rating: review_data[:average]
  )
rescue Mongoid::Errors::DocumentNotFound
  # we're ok if the product doesn't exist
end