Class: Bulkrax::DownloadCloudFileJob
- Inherits:
-
ApplicationJob
- Object
- ActiveJob::Base
- ApplicationJob
- Bulkrax::DownloadCloudFileJob
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- app/jobs/bulkrax/download_cloud_file_job.rb
Instance Method Summary collapse
-
#perform(file, target_file) ⇒ Object
Retrieve cloud file and write to the imports directory Note: if using the file system, the mounted directory in browse_everything MUST be shared by web and worker servers.
Instance Method Details
#perform(file, target_file) ⇒ Object
Retrieve cloud file and write to the imports directory Note: if using the file system, the mounted directory in
browse_everything MUST be shared by web and worker servers
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/jobs/bulkrax/download_cloud_file_job.rb', line 11 def perform(file, target_file) retriever = BrowseEverything::Retriever.new last_logged_time = Time.zone.now log_interval = 3.seconds retriever.download(file, target_file) do |filename, retrieved, total| percentage = (retrieved.to_f / total.to_f) * 100 current_time = Time.zone.now if (current_time - last_logged_time) >= log_interval # Use number_to_human_size for formatting readable_retrieved = number_to_human_size(retrieved) readable_total = number_to_human_size(total) Rails.logger.info "Downloaded #{readable_retrieved} of #{readable_total}, #{filename}: #{percentage.round}% complete" last_logged_time = current_time end end Rails.logger.info "Download complete: #{file['url']} to #{target_file}" end |