6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'app/workers/limit_points_adjustment_worker.rb', line 6
def perform(points_adjustment_id)
success = false
ActiveRecord::Base.transaction do
points_adjustment = LimitPointsAdjustment.find(points_adjustment_id)
raise "Points adjustment campaign status is not 'on_queue'" if points_adjustment.status != 'on_queue'
limit_points_adjustment_active = LimitPointsAdjustment.find_by(status: 'active')
if limit_points_adjustment_active.present?
limit_points_adjustment_active.update!(status: 'expired', ended_at: Time.zone.now)
end
points_adjustment.update!(status: 'active')
LimitPointsUsage.unscoped.in_batches(of: 1000).delete_all
success = true
end
raise 'Something went wrong' if !success
rescue StandardError => e
APMErrorHandler.report(e, limit_points_adjustment_id: points_adjustment_id)
end
|