5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/workers/catalog_price_changes_alert_worker.rb', line 5
def perform
@main_catalogs = ViewProductCatalog.where(price_updated_at: 1.day.ago.beginning_of_day..1.day.ago.end_of_day)
.where(catalog_id: Catalog.price_alert_catalog_ids)
.where.not(old_price: nil)
.order(:item_id, :catalog_id)
.select(:catalog_item_id, :item_sku, :catalog_id, :catalog_name, :currency_symbol, :price, :old_price, :sale_price, :price_updated_at)
@other_catalogs = ViewProductCatalog.where(price_updated_at: 1.day.ago.beginning_of_day..1.day.ago.end_of_day)
.where.not(catalog_id: Catalog.price_alert_catalog_ids)
.where.not(old_price: nil)
.order('3 desc')
.select('catalog_id, catalog_name, count(id) as num_items')
.group(:catalog_id, :catalog_name)
if (Date.yesterday.wday != 0 || Date.yesterday.wday != 6) && (@main_catalogs.present? || @other_catalogs.present?)
InternalMailer.catalog_price_changes_alert(@main_catalogs, @other_catalogs).deliver_now
end
end
|