Class: IiifPrint::Jobs::RequestSplitPdfJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/iiif_print/jobs/request_split_pdf_job.rb

Overview

Encapsulates logic for cleanup when the PDF is destroyed after pdf splitting into child works

Instance Method Summary collapse

Instance Method Details

#perform(file_set_id:, user:) ⇒ Object

rubocop:disable Metrics/MethodLength



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

def perform(file_set_id:, user:)
  file_set = IiifPrint.find_by(id: file_set_id)
  return true unless IiifPrint.pdf?(file_set)
  work = IiifPrint.parent_for(file_set)

  # Woe is ye who changes the configuration of the model, thus removing the splitting.
  raise WorkNotConfiguredToSplitFileSetError.new(work: work, file_set: file_set) unless work&.iiif_print_config&.pdf_splitter_job&.presence

  # clean up any existing spawned child works of this file_set
  IiifPrint::SplitPdfs::DestroyPdfChildWorksService.conditionally_destroy_spawned_children_of(
    file_set: file_set,
    work: work,
    user: user
  )

  location = IiifPrint.pdf_path_for(file_set: file_set)
  IiifPrint.conditionally_submit_split_for(work: work, file_set: file_set, locations: [location], user: user)
end