Class: ImportUrlJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/import_url_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(file_set, log) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/jobs/import_url_job.rb', line 13

def perform(file_set, log)
  log.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

    # attach downloaded file to FileSet stubbed out
    if CurationConcerns::Actors::FileSetActor.new(file_set, user).create_content(f)
      # send message to user on download success
      CurationConcerns.config.callback.run(:after_import_url_success, file_set, user)
      log.success!
    else
      CurationConcerns.config.callback.run(:after_import_url_failure, file_set, user)
      log.fail!(file_set.errors.full_messages.join(' '))
    end
  end
end