From eb480e0537991da684ce0ff4c0e54388e755dd0a Mon Sep 17 00:00:00 2001 From: Rory McNicholl Date: Tue, 23 Jul 2024 14:43:28 +0100 Subject: [PATCH] more debug for importUrlJob --- config/initializers/import_url_job_overrides.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/initializers/import_url_job_overrides.rb b/config/initializers/import_url_job_overrides.rb index 2447fcd7..58b97356 100644 --- a/config/initializers/import_url_job_overrides.rb +++ b/config/initializers/import_url_job_overrides.rb @@ -1,5 +1,22 @@ ImportUrlJob.class_eval do + def copy_remote_file(uri, name, headers = {}) + filename = File.basename(name) + dir = Dir.mktmpdir + Rails.logger.debug("ImportUrlJob: Copying <#{uri}> to #{dir}") + + File.open(File.join(dir, filename), 'wb') do |f| + begin + write_file(uri, f, headers) + yield f + rescue StandardError => e + STDERR.puts("IMPORT URL ERROR: #{e}") + send_error(e.message) + end + end + Rails.logger.debug("ImportUrlJob: Closing #{File.join(dir, filename)}") + end + def send_error(error_message) user = User.find_by_user_key(file_set.depositor) @file_set.errors.add('Error:', error_message)