Sha256: 2545d8bfb383963af5e4e7a69b8974dbff1571daf42c45009c4591387dc9aede

Contents?: true

Size: 1.01 KB

Versions: 28

Compression:

Stored size: 1.01 KB

Contents

module Workarea
  class SaveOrderMetrics
    include Sidekiq::Worker
    include Sidekiq::CallbacksWorker
    include SaveMetrics

    sidekiq_options enqueue_on: { Order => :place }, queue: 'low'

    class << self
      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

      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
    end

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

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.26 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.25 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.23 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.22 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.21 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.20 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.19 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.18 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.17 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.16 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.15 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.14 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.13 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.12 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.11 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.10 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.9 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.8 app/workers/workarea/save_order_metrics.rb
workarea-core-3.5.7 app/workers/workarea/save_order_metrics.rb