Class: Etna::Clients::Metis::MetisDownloadWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Metis::MetisDownloadWorkflow
- Defined in:
- lib/etna/clients/metis/workflows/metis_download_workflow.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
Returns the value of attribute bucket_name.
-
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
-
#metis_client ⇒ Object
Returns the value of attribute metis_client.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
-
#do_download(dest_file_or_io, metis_file, &block) ⇒ Object
TODO: Might be possible to use range headers to select and resume downloads on failure in the future.
-
#initialize(args) ⇒ MetisDownloadWorkflow
constructor
A new instance of MetisDownloadWorkflow.
Constructor Details
#initialize(args) ⇒ MetisDownloadWorkflow
Returns a new instance of MetisDownloadWorkflow.
11 12 13 |
# File 'lib/etna/clients/metis/workflows/metis_download_workflow.rb', line 11 def initialize(args) super({max_attempts: 3}.update(args)) end |
Instance Attribute Details
#bucket_name ⇒ Object
Returns the value of attribute bucket_name
9 10 11 |
# File 'lib/etna/clients/metis/workflows/metis_download_workflow.rb', line 9 def bucket_name @bucket_name end |
#max_attempts ⇒ Object
Returns the value of attribute max_attempts
9 10 11 |
# File 'lib/etna/clients/metis/workflows/metis_download_workflow.rb', line 9 def max_attempts @max_attempts end |
#metis_client ⇒ Object
Returns the value of attribute metis_client
9 10 11 |
# File 'lib/etna/clients/metis/workflows/metis_download_workflow.rb', line 9 def metis_client @metis_client end |
#project_name ⇒ Object
Returns the value of attribute project_name
9 10 11 |
# File 'lib/etna/clients/metis/workflows/metis_download_workflow.rb', line 9 def project_name @project_name end |
Instance Method Details
#do_download(dest_file_or_io, metis_file, &block) ⇒ Object
TODO: Might be possible to use range headers to select and resume downloads on failure in the future.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/etna/clients/metis/workflows/metis_download_workflow.rb', line 16 def do_download(dest_file_or_io, metis_file, &block) size = metis_file.size completed = 0.0 start = Time.now unless dest_file_or_io.is_a?(IO) || dest_file_or_io.is_a?(StringIO) ::File.open(dest_file_or_io, 'w') do |io| return do_download(dest_file_or_io, metis_file, &block) end end metis_client.download_file(metis_file) do |chunk| dest_file_or_io.write chunk completed += chunk.size block.call([ :progress, size == 0 ? 1 : completed / size, (completed / (Time.now - start)).round(2), ]) unless block.nil? end end |