Class: SourceMonitor::ItemCleanupJob

Inherits:
ApplicationJob show all
Defined in:
app/jobs/source_monitor/item_cleanup_job.rb

Constant Summary collapse

DEFAULT_BATCH_SIZE =
100

Instance Method Summary collapse

Methods inherited from ApplicationJob

source_monitor_queue

Instance Method Details

#perform(options = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/jobs/source_monitor/item_cleanup_job.rb', line 14

def perform(options = nil)
  options = SourceMonitor::Jobs::CleanupOptions.normalize(options)

  scope = resolve_scope(options)
  batch_size = SourceMonitor::Jobs::CleanupOptions.batch_size(options, default: DEFAULT_BATCH_SIZE)
  now = SourceMonitor::Jobs::CleanupOptions.resolve_time(options[:now])
  strategy = resolve_strategy(options)
  pruner_class = options[:retention_pruner_class] || SourceMonitor::Items::RetentionPruner

  scope.find_in_batches(batch_size:) do |batch|
    batch.each do |source|
      pruner_class.call(source:, now:, strategy:)
    end
  end
end