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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_setObject (readonly)

Returns the value of attribute file_set.



11
12
13
# File 'app/jobs/import_url_job.rb', line 11

def file_set
  @file_set
end

#operationObject (readonly)

Returns the value of attribute operation.



11
12
13
# File 'app/jobs/import_url_job.rb', line 11

def operation
  @operation
end

Instance Method Details

#perform(file_set, operation, headers = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/jobs/import_url_job.rb', line 20

def perform(file_set, operation, headers = {})
  operation.performing!
  user = User.find_by_user_key(file_set.depositor)
  uri = URI(file_set.import_url)
  name = file_set.label

  @file_set = file_set
  @operation = operation

  unless BrowseEverything::Retriever.can_retrieve?(uri, headers)
    send_error('Expired URL')
    return false
  end

  # @todo Use Hydra::Works::AddExternalFileToFileSet instead of manually
  #       copying the file here. This will be gnarly.
  copy_remote_file(uri, name, headers) 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.
    log_import_status(uri, f, user)
  end
end