Class: Spotlight::RemoveTagsJob

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

Instance Method Summary collapse

Methods included from GatherDocuments

#each_document

Methods included from JobTracking

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

Instance Method Details

#perform(solr_params:, exhibit:, tags:) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



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

def perform(solr_params:, exhibit:, tags:, **)
  @errors = 0

  each_document(solr_params, exhibit) do |document|
    sidecar = document.sidecar(exhibit)
    all_tags = sidecar.all_tags_list
    all_tags -= tags
    exhibit.tag(document.sidecar(exhibit), with: all_tags, on: :tags)
    document.reindex(update_params: {})
    progress&.increment
  rescue StandardError => e
    job_tracker.append_log_entry(type: :error, exhibit:, message: e.to_s)
    @errors += 1
    mark_job_as_failed!
  end
  exhibit.blacklight_config.repository.connection.commit
  job_tracker.append_log_entry(type: :info, exhibit:, message: "#{progress.progress} of #{progress.total} (#{@errors} errors)")
end