-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit will bring in changes from `5.3.1-british_library` to move the download of cloud files to a background job.
- Loading branch information
Showing
2 changed files
with
17 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bulkrax | ||
class DownloadCloudFileJob < ApplicationJob | ||
queue_as Bulkrax.config.ingest_queue_name | ||
|
||
include ActionView::Helpers::NumberHelper | ||
|
||
# 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 | ||
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| | ||
# The block is still useful for showing progress, but the | ||
# first argument is the filename instead of a chunk of data. | ||
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters