Skip to content

Commit

Permalink
Merge pull request #6370 from samvera/valk_ch12n_job
Browse files Browse the repository at this point in the history
Perform characterization on valkyrie resources in a job
  • Loading branch information
abelemlih authored Oct 19, 2023
2 parents 368fe3c + 99e0a42 commit d75f3d0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/jobs/characterize_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def characterize(file_set, _file_id, filepath) # rubocop:disable Metrics/AbcSize
# value. So later we'll ensure it's set to the new file's filename.
reset_title = file_set.title.first == file_set.label

characterization_service.run(file_set.characterization_proxy, filepath)
characterization_service.run(file_set.characterization_proxy, filepath, **Hyrax.config.characterization_options)
Hyrax.logger.debug "Ran characterization on #{file_set.characterization_proxy.id} (#{file_set.characterization_proxy.mime_type})"
file_set.characterization_proxy.alpha_channels = channels(filepath) if file_set.image? && Hyrax.config.iiif_image_server?
file_set.characterization_proxy.save!
Expand Down
9 changes: 9 additions & 0 deletions app/jobs/valkyrie_characterization_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
class ValkyrieCharacterizationJob < Hyrax::ApplicationJob
queue_as Hyrax.config.ingest_queue_name
def perform(file_metadata_id)
file_metadata = Hyrax.custom_queries.find_file_metadata_by(id: file_metadata_id)
Hyrax.config.characterization_service
.run(metadata: file_metadata, file: file_metadata.file, **Hyrax.config.characterization_options)
end
end
4 changes: 1 addition & 3 deletions app/services/hyrax/listeners/file_metadata_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def on_file_uploaded(event)
# Run characterization for original file only
return unless event[:metadata]&.original_file?

Hyrax.config
.characterization_service
.run(metadata: event[:metadata], file: event[:metadata].file, **Hyrax.config.characterization_options)
ValkyrieCharacterizationJob.perform_later(event[:metadata].id.to_s)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/jobs/characterize_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

before do
allow(FileSet).to receive(:find).with(file_set_id).and_return(file_set)
allow(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename)
allow(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename, **Hyrax.config.characterization_options)
allow(CreateDerivativesJob).to receive(:perform_later).with(file_set, file.id, filename)
end

Expand All @@ -36,7 +36,7 @@

it 'skips Hyrax::WorkingDirectory.copy_repository_resource_to_working_directory' do
expect(Hyrax::WorkingDirectory).not_to receive(:copy_repository_resource_to_working_directory)
expect(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename)
expect(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename, **Hyrax.config.characterization_options)
described_class.perform_now(file_set, file.id, filename)
end
end
Expand All @@ -46,14 +46,14 @@

it 'uses Hyrax::WorkingDirectory.copy_repository_resource_to_working_directory to pull the repo file' do
expect(Hyrax::WorkingDirectory).to receive(:copy_repository_resource_to_working_directory)
expect(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename)
expect(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename, **Hyrax.config.characterization_options)
described_class.perform_now(file_set, file.id, filename)
end
end

context 'when the characterization proxy content is present' do
it 'runs Hydra::Works::CharacterizationService and creates a CreateDerivativesJob' do
expect(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename)
expect(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename, **Hyrax.config.characterization_options)
expect(file).to receive(:save!)
expect(file_set).to receive(:update_index)
expect(CreateDerivativesJob).to receive(:perform_later).with(file_set, file.id, filename)
Expand All @@ -70,7 +70,7 @@

context 'FileSet with preexisting characterization metadata getting a new version' do
before do
allow(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename)
allow(Hydra::Works::CharacterizationService).to receive(:run).with(file, filename, **Hyrax.config.characterization_options)
allow(CreateDerivativesJob).to receive(:perform_later).with(file_set, file.id, filename)
end

Expand Down
19 changes: 19 additions & 0 deletions spec/jobs/valkyrie_characterization_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'spec_helper'

RSpec.describe ValkyrieCharacterizationJob, valkyrie_adapter: :test_adapter do
context 'with a file' do
let(:file_metadata) { FactoryBot.valkyrie_create(:hyrax_file_metadata) }
let(:file) { double }

before do
allow(file_metadata).to receive(:file).and_return(file)
allow(Hyrax.custom_queries).to receive(:find_file_metadata_by).with(id: file_metadata.id).and_return(file_metadata)
end

it 'calls the characterization service' do
expect(Hyrax.config.characterization_service).to receive(:run).with(metadata: file_metadata, file: file, **Hyrax.config.characterization_options)
described_class.perform_now(file_metadata.id)
end
end
end

0 comments on commit d75f3d0

Please sign in to comment.