Class: Workarea::SaveOrderMetrics

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.perform(order) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/workers/workarea/save_order_metrics.rb', line 10

def perform(order)
  return if order.metrics_saved?
  metrics = OrderMetrics.new(order)

  save_sales(metrics)
  save_user(metrics)
  save_catalog(metrics)
  save_traffic(metrics)
  save_pricing(metrics)
  save_tenders(metrics)
  save_segments(metrics)

  order.metrics_saved!
end

.save_user(metrics) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/workers/workarea/save_order_metrics.rb', line 25

def save_user(metrics)
  Metrics::User.save_order(at: metrics.occured_at, **metrics.user_data)
  Metrics::User.save_affinity(
    id: metrics.email,
    action: 'purchased',
    product_ids: metrics.products.keys,
    category_ids: metrics.categories.keys,
    search_ids: metrics.searches.keys
  )
end

Instance Method Details

#perform(order_id) ⇒ Object



37
38
39
# File 'app/workers/workarea/save_order_metrics.rb', line 37

def perform(order_id)
  self.class.perform(Order.find(order_id))
end