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:, user:) ⇒ Object

rubocop:disable Metrics/MethodLength

Parameters:

  • file_set (FileSet)
  • user (User)

Raises:



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:, user:)
  return true unless file_set.pdf?

  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
  )

  location = Hyrax::WorkingDirectory.find_or_retrieve(file_set.files.first.id, file_set.id)

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