From f1111f1c4f456f763b3426f22e2da7734303a615 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Tue, 18 Jul 2023 13:28:11 -0400 Subject: [PATCH] WIP --- .../split_pdfs/derivative_rodeo_splitter.rb | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb b/lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb index 90b1d85f..97242ee1 100644 --- a/lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb +++ b/lib/iiif_print/split_pdfs/derivative_rodeo_splitter.rb @@ -16,7 +16,7 @@ class DerivativeRodeoSplitter # # @return [Array] paths to images split from each page of PDF file def self.call(filename, file_set:) - new(filename, file_set: file_set).split_files + new(filename, file_set: file_set).call end def initialize(filename, file_set:, output_tmp_dir: Dir.tmpdir) @@ -60,13 +60,23 @@ def initialize(filename, file_set:, output_tmp_dir: Dir.tmpdir) attr_reader :preprocessed_location_template ## - # @return [Array] the paths to each of the images split off from the PDF. + # @return [Array] the local paths to each of the images split off from the PDF. + def call + # TODO: Could we off-load the copy to another job? I'm afraid of the "cost" of copying + # a large number of files. + copy(split_files) + end + + private + + ## + # @return [Array] def split_files DerivativeRodeo::Generators::PdfSplitGenerator.new( input_uris: [@input_uri], output_location_template: output_location_template, preprocessed_location_template: preprocessed_location_template - ).generated_files.map(&:file_path) + ).generated_files rescue => e message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \ "input_uri: #{@input_uri.inspect}, " \ @@ -74,6 +84,25 @@ def split_files "preprocessed_location_template: #{preprocessed_location_template.inspect}." exception = RuntimeError.new(message) exception.set_backtrace(e.backtrace) + DerivativeRodeo.logger.error(message) + raise exception + end + + ## + # @param [Array] + # @return [Array] + def copy(generated_files) + DerivativeRodeo::Generators::CopyGenerator.new( + input_uris: generated_files.map(&:file_uri), + output_location_template: output_location_template + ).generated_files.map(&:file_path) + rescue => e + message = "#{self.class}##{__method__} encountered `#{e.class}' “#{e}” for " \ + "input_uri: #{@input_uri.inspect}, " \ + "output_location_template: #{output_location_template.inspect}" + exception = RuntimeError.new(message) + exception.set_backtrace(e.backtrace) + DerivativeRodeo.logger.error(message) raise exception end end