Class: Workarea::ProcessProductRecommendations
- Inherits:
-
Object
- Object
- Workarea::ProcessProductRecommendations
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/workarea/process_product_recommendations.rb
Instance Method Summary collapse
Instance Method Details
#add(order) ⇒ Object
22 23 24 25 |
# File 'app/workers/workarea/process_product_recommendations.rb', line 22 def add(order) product_ids = order.items.map(&:product_id) predictor.orders.add_set(order.id.to_s, product_ids) if product_ids.many? end |
#page_size ⇒ Object
27 28 29 |
# File 'app/workers/workarea/process_product_recommendations.rb', line 27 def page_size Workarea.config.product_recommendation_index_page_size end |
#perform ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/workers/workarea/process_product_recommendations.rb', line 5 def perform(*) predictor.clean! start = Workarea.config.recommendation_expiration.ago Order .where(:placed_at.gte => start) .desc(:placed_at) # sort by placed_at to ensure use of that index .each_by(page_size) { |order| add(order) } predictor.process! end |
#predictor ⇒ Object
18 19 20 |
# File 'app/workers/workarea/process_product_recommendations.rb', line 18 def predictor @predictor ||= Recommendation::ProductPredictor.new end |