Class: Workarea::DeactivateStaleDiscounts
- Inherits:
-
Object
- Object
- Workarea::DeactivateStaleDiscounts
- Includes:
- Sidekiq::Worker
- Defined in:
- app/workers/workarea/deactivate_stale_discounts.rb
Instance Method Summary collapse
- #all_active_discount_ids ⇒ Object
- #order_discount_ids ⇒ Object
- #perform(*args) ⇒ Object
- #shipping_discount_ids ⇒ Object
- #unused_discount_ids ⇒ Object
- #used_discount_ids ⇒ Object
Instance Method Details
#all_active_discount_ids ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/workers/workarea/deactivate_stale_discounts.rb', line 30 def all_active_discount_ids Pricing::Discount .where(:updated_at.lt => Workarea.config.discount_staleness_ttl.ago) .select(&:active?) .map(&:id) .map(&:to_s) end |
#order_discount_ids ⇒ Object
20 21 22 |
# File 'app/workers/workarea/deactivate_stale_discounts.rb', line 20 def order_discount_ids Order.since(Workarea.config.discount_staleness_ttl.ago).discount_ids end |
#perform(*args) ⇒ Object
5 6 7 8 9 |
# File 'app/workers/workarea/deactivate_stale_discounts.rb', line 5 def perform(*args) Mongoid::AuditLog.record do Pricing::Discount.any_in(id: unused_discount_ids).auto_deactivate end end |
#shipping_discount_ids ⇒ Object
24 25 26 27 28 |
# File 'app/workers/workarea/deactivate_stale_discounts.rb', line 24 def shipping_discount_ids Shipping .since(Workarea.config.discount_staleness_ttl.ago) .discount_ids end |
#unused_discount_ids ⇒ Object
11 12 13 |
# File 'app/workers/workarea/deactivate_stale_discounts.rb', line 11 def unused_discount_ids all_active_discount_ids - used_discount_ids end |
#used_discount_ids ⇒ Object
15 16 17 18 |
# File 'app/workers/workarea/deactivate_stale_discounts.rb', line 15 def used_discount_ids @used_discount_ids ||= (order_discount_ids + shipping_discount_ids).map(&:to_s).uniq end |