Class: IngestFileJob

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

Instance Method Summary collapse

Methods included from CurationConcerns::Lockable

#acquire_lock_for, #lock_manager

Instance Method Details

#perform(file_set, filepath, user, opts = {}) ⇒ Object

Parameters:

  • file_set (FileSet)
  • filepath (String)

    the cached file within the CurationConcerns.config.working_path

  • user (User)
  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • mime_type (String)
  • filename (String)
  • relation, (String)

    ex. :original_file



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/jobs/ingest_file_job.rb', line 12

def perform(file_set, filepath, user, opts = {})
  relation = opts.fetch(:relation, :original_file).to_sym

  # Wrap in an IO decorator to attach passed-in options
  local_file = Hydra::Derivatives::IoDecorator.new(File.open(filepath, "rb"))
  local_file.mime_type = opts.fetch(:mime_type, nil)
  local_file.original_name = opts.fetch(:filename, File.basename(filepath))

  # Prevent other jobs from trying to modify the FileSet at the same time
  acquire_lock_for(file_set.id) do
    # Tell AddFileToFileSet service to skip versioning because versions will be minted by
    # VersionCommitter when necessary during save_characterize_and_record_committer.
    Hydra::Works::AddFileToFileSet.call(file_set,
                                        local_file,
                                        relation,
                                        versioning: false)
    # Persist changes to the file_set
    file_set.save!
  end

  repository_file = file_set.send(relation)

  # Do post file ingest actions
  CurationConcerns::VersioningService.create(repository_file, user)

  # TODO: this is a problem, the file may not be available at this path on another machine.
  # It may be local, or it may be in s3
  CharacterizeJob.perform_later(file_set, repository_file.id, filepath)
end