Class: CharacterizeJob

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

Overview

a ActiveJob job to process file characterization.

the characterization process is handled by a service object, which is configurable via #characterization_service.

end

Examples:

setting a custom characterization service

class MyCharacterizer
  def run(file, path)
    # do custom characterization
  end
end

# in a Rails initializer
CharacterizeJob.characterization_service = MyCharacterizer.new

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



30
31
32
33
34
35
36
37
38
39
40
# File 'app/jobs/characterize_job.rb', line 30

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?
  # Ensure a fresh copy of the repo file's latest version is being worked on, if no filepath is directly provided
  filepath = Hyrax::WorkingDirectory.copy_repository_resource_to_working_directory(Hydra::PCDM::File.find(file_id), file_set.id) unless filepath && File.exist?(filepath)
  characterize(file_set, file_id, filepath)

  Hyrax.publisher.publish('file.characterized',
                          file_set: file_set,
                          file_id: file_id,
                          path_hint: filepath)
end