Class: ImportUrlJob

Inherits:
ActiveJob::Base
  • Object
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
41
42
# 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)

  Tempfile.open(file_set.id.tr('/', '_')) do |f|
    copy_remote_file(file_set, f)

    # reload the FileSet once the data is copied since this is a long running task
    file_set.reload

    # We invoke the FileSetActor in a synchronous way so that this tempfile is available
    # when IngestFileJob is invoked. If it was asynchronous the IngestFileJob may be invoked
    # on a machine that did not have this temp file on it's 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, 'original_file', false)
      # send message to user on download success
      Hyrax.config.callback.run(:after_import_url_success, file_set, user)
      operation.success!
    else
      Hyrax.config.callback.run(:after_import_url_failure, file_set, user)
      operation.fail!(file_set.errors.full_messages.join(' '))
    end
  end
end