Class: RailsOrbit::RetentionJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/rails_orbit/retention_job.rb

Constant Summary collapse

BATCH_SIZE =
1_000

Instance Method Summary collapse

Instance Method Details

#performObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/rails_orbit/retention_job.rb', line 7

def perform
  days  = RailsOrbit.configuration.retention_days
  total = 0

  loop do
    ids = Metric.older_than(days).limit(BATCH_SIZE).pluck(:id)
    break if ids.empty?
    deleted = Metric.where(id: ids).delete_all
    total += deleted
    break if ids.size < BATCH_SIZE
  end

  Rails.logger.info "[rails_orbit] RetentionJob: purged #{total} metrics older than #{days} days."
end