Class: Workarea::Insights::NewProducts

Inherits:
Base
  • Object
show all
Defined in:
app/models/workarea/insights/new_products.rb

Class Method Summary collapse

Methods inherited from Base

beginning_of_last_month, current, end_of_last_month, generate_monthly!, generate_weekly!, #include?, #slug

Methods included from ApplicationDocument

#releasable?

Methods included from Sidekiq::Callbacks

assert_valid_config!, async, disable, enable, inline, #run_callbacks

Methods included from Mongoid::Document

#embedded_children

Class Method Details

.beginning_of_yestedayObject



23
24
25
# File 'app/models/workarea/insights/new_products.rb', line 23

def beginning_of_yesteday
  Time.current.yesterday.beginning_of_day
end

.dashboardsObject



5
6
7
# File 'app/models/workarea/insights/new_products.rb', line 5

def dashboards
  %w(catalog)
end

.end_of_yesterdayObject



27
28
29
# File 'app/models/workarea/insights/new_products.rb', line 27

def end_of_yesterday
  Time.current.yesterday.end_of_day
end

.generate_daily!Object



9
10
11
12
# File 'app/models/workarea/insights/new_products.rb', line 9

def generate_daily!
  results = generate_results
  create!(results: results) if results.present?
end

.generate_resultsObject



14
15
16
17
18
19
20
21
# File 'app/models/workarea/insights/new_products.rb', line 14

def generate_results
  Catalog::Product
    .where(:created_at.gte => beginning_of_yesteday)
    .where(:created_at.lte => end_of_yesterday)
    .order(created_at: :desc)
    .limit(Workarea.config.insights_products_list_max_results)
    .map { |result| { product_id: result['_id'] } }
end