Class: CharacterizeJob

Inherits:
Hyrax::ApplicationJob show all
Defined in:
app/jobs/characterize_job.rb

Instance Method Summary collapse

Instance Method Details

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

Characterizes the file at ‘filepath’ if available, otherwise, pulls a copy from the repository and runs characterization on that file.

Parameters:

  • file_set (FileSet)
  • file_id (String)

    identifier for a Hydra::PCDM::File

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

    the cached file within the Hyrax.config.working_path



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

def perform(file_set, file_id, filepath = nil)
  raise "#{file_set.class.characterization_proxy} was not found for FileSet #{file_set.id}" unless file_set.characterization_proxy?
  filepath = Hyrax::WorkingDirectory.find_or_retrieve(file_id, file_set.id) unless filepath && File.exist?(filepath)
  Hydra::Works::CharacterizationService.run(file_set.characterization_proxy, filepath)
  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
  CreateDerivativesJob.perform_later(file_set, file_id, filepath)
end