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
# 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?
  filepath = Hyrax::WorkingDirectory.find_or_retrieve(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