Class: ScheduleWorkers::LimitPointsResetWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- ScheduleWorkers::LimitPointsResetWorker
- Defined in:
- app/workers/schedule_workers/limit_points_reset_worker.rb
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Instance Method Details
#perform ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/workers/schedule_workers/limit_points_reset_worker.rb', line 11 def perform ActiveRecord::Base.transaction do batch_size = 1000 # [1] Delete all LimitPointsUsage records that have remaining_limit_days = 1 or nil LimitPointsUsage.where(remaining_limit_days: [1, nil]).in_batches(of: batch_size).delete_all # [2] Decrease remaining_limit_days by 1 for all LimitPointsUsage records that have remaining_limit_days > 1 LimitPointsUsage.where.not(remaining_limit_days: [1, nil]).in_batches(of: batch_size) do |batch| batch.update_all('remaining_limit_days = remaining_limit_days - 1') end end rescue StandardError => e APMErrorHandler.report e raise e end |