Class: Spotlight::ReindexExhibitJob

Inherits:
ApplicationJob show all
Includes:
JobTracking, LimitConcurrency
Defined in:
app/jobs/spotlight/reindex_exhibit_job.rb

Overview

Reindex an exhibit by parallelizing resource indexing into multiple batches of reindex jobs

Constant Summary

Constants included from LimitConcurrency

LimitConcurrency::VALIDITY_TOKEN_PARAMETER

Instance Method Summary collapse

Methods included from JobTracking

#finalize_job_tracker!, #initialize_job_tracker!, #job_tracker, #mark_job_as_failed!

Instance Method Details

#perform(exhibit, batch_size: Spotlight::Engine.config.reindexing_batch_size, batch_count: Spotlight::Engine.config.reindexing_batch_count) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/jobs/spotlight/reindex_exhibit_job.rb', line 12

def perform(exhibit, batch_size: Spotlight::Engine.config.reindexing_batch_size, batch_count: Spotlight::Engine.config.reindexing_batch_count, **)
  count = exhibit.resources.count

  # Use the provided batch size, or calculate a reasonable default
  batch_count = (count.to_f / batch_size).ceil if batch_size
  batch_count ||= batch_count_based_on_number_of_resources(count)

  return Spotlight::ReindexJob.perform_now(exhibit, reports_on: job_tracker) if batch_count == 1

  batch_size ||= (count.to_f / batch_count).ceil

  perform_later_in_batches(exhibit, of: batch_size)

  # mark the job as 'pending' and let the UpdateJobTrackersJob finalize this status after the ReindexJobs finish
  job_tracker.update(status: 'pending')
end