Class: CharacterizeJob

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
CurationConcerns::Lockable
Defined in:
app/jobs/characterize_job.rb

Instance Method Summary collapse

Methods included from CurationConcerns::Lockable

#acquire_lock_for, #lock_manager

Instance Method Details

#perform(file_set, file_id, filepath = nil) ⇒ Object

Parameters:

  • file_set (FileSet)
  • file_id (String)

    identifier for a Hydra::PCDM::File

  • filepath (String, NilClass) (defaults to: nil)

    the cached file within the CurationConcerns.config.working_path

Raises:

  • (LoadError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/jobs/characterize_job.rb', line 9

def perform(file_set, file_id, filepath = nil)
  filename = CurationConcerns::WorkingDirectory.find_or_retrieve(file_id, file_set.id, filepath)
  raise LoadError, "#{file_set.class.characterization_proxy} was not found" unless file_set.characterization_proxy?

  # Prevent other jobs from trying to modify the FileSet at the same time
  acquire_lock_for(file_set.id) do
    Hydra::Works::CharacterizationService.run(file_set.characterization_proxy, filename)
    Rails.logger.debug "Ran characterization on #{file_set.characterization_proxy.id} (#{file_set.characterization_proxy.mime_type})"
    file_set.characterization_proxy.save!
    file_set.update_index
    file_set.parent.in_collections.each(&:update_index) if file_set.parent
  end

  CreateDerivativesJob.perform_later(file_set, file_id, filename)
end