Class: Maintenance::CouponMaintenance
- Inherits:
-
BaseService
- Object
- BaseService
- Maintenance::CouponMaintenance
- Defined in:
- app/services/maintenance/coupon_maintenance.rb
Overview
This class takes care of inactivating expired coupons.
Instance Method Summary collapse
- #inactivate_expired_coupons ⇒ Object
- #process ⇒ Object
- #synchronize_promotions_with_coupons ⇒ Object
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#inactivate_expired_coupons ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/services/maintenance/coupon_maintenance.rb', line 10 def inactivate_expired_coupons # Safe assumption that if your coupon is expired more than 3 months ago, it's expired and can be inactivated Coupon.transaction do Coupon.expired(3.months.ago).active.find_each do |coupon| logger.info "Coupon #{coupon.id} is expired and has been inactivated" coupon.update!(is_inactive: true) end end end |
#process ⇒ Object
3 4 5 6 7 8 |
# File 'app/services/maintenance/coupon_maintenance.rb', line 3 def process PaperTrail.request(whodunnit: 'Maintenance::CouponMaintenance') do inactivate_expired_coupons synchronize_promotions_with_coupons end end |
#synchronize_promotions_with_coupons ⇒ Object
20 21 22 23 |
# File 'app/services/maintenance/coupon_maintenance.rb', line 20 def synchronize_promotions_with_coupons results = Coupon::PromoItemSync.new(logger:).process InternalMailer.promo_item_sync_notification(results).deliver end |