Class: ImportUrlJob

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

Overview

Given a FileSet that has an import_url property, download that file and put it into Fedora Called by AttachFilesToWorkJob (when files are uploaded to s3) and CreateWithRemoteFilesActor when files are located in some other service.

Instance Method Summary collapse

Instance Method Details

#perform(file_set, operation) ⇒ Object

Parameters:



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/import_url_job.rb', line 19

def perform(file_set, operation)
  operation.performing!
  user = User.find_by_user_key(file_set.depositor)
  uri = URI(file_set.import_url)
  # @todo Use Hydra::Works::AddExternalFileToFileSet instead of manually
  #       copying the file here. This will be gnarly.
  copy_remote_file(uri) do |f|
    # reload the FileSet once the data is copied since this is a long running task
    file_set.reload

    # FileSetActor operates synchronously so that this tempfile is available.
    # If asynchronous, the job might be invoked on a machine that did not have this temp file on its file system!
    # NOTE: The return status may be successful even if the content never attaches.
    if Hyrax::Actors::FileSetActor.new(file_set, user).create_content(f, from_url: true)
      operation.success!
    else
      # send message to user on download failure
      Hyrax.config.callback.run(:after_import_url_failure, file_set, user)
      operation.fail!(file_set.errors.full_messages.join(' '))
    end
  end
end