Class: SourceArchivalWorker

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

Overview

Sidekiq worker: source archival.

Constant Summary collapse

DEFAULT_STALE_MONTHS =

Default stale months.

36

Instance Method Summary collapse

Instance Method Details

#perform(stale_months: DEFAULT_STALE_MONTHS) ⇒ Object

Runs the job.

Parameters:

  • stale_months (Object) (defaults to: DEFAULT_STALE_MONTHS)

    the stale months

Returns:

  • (Object)

    the result



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/workers/source_archival_worker.rb', line 16

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