Class: SourceArchivalWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/workers/source_archival_worker.rb

Constant Summary collapse

DEFAULT_STALE_MONTHS =
36

Instance Method Summary collapse

Instance Method Details

#perform(stale_months: DEFAULT_STALE_MONTHS) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/workers/source_archival_worker.rb', line 10

def perform(stale_months: DEFAULT_STALE_MONTHS)
  cutoff = stale_months.to_i.months.ago
  preserve_ids = build_preserve_set(cutoff)
  preserve_ids << Source::UNKNOWN_ID

  archived_count = Source
    .where(visibility: :active)
    .where.not(id: preserve_ids)
    .update_all(visibility: :archived)

  logger.info "SourceArchivalWorker: Archived #{archived_count} sources " \
              "with no activity since #{cutoff.to_date} " \
              "(#{preserve_ids.size} preserved)"
end