Class: Etna::Clients::Metis::SyncMetisDataWorkflow
- Inherits:
-
Struct
- Object
- Struct
- Etna::Clients::Metis::SyncMetisDataWorkflow
- Defined in:
- lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb
Instance Attribute Summary collapse
-
#bucket_name ⇒ Object
Returns the value of attribute bucket_name.
-
#filesystem ⇒ Object
Returns the value of attribute filesystem.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#metis_client ⇒ Object
Returns the value of attribute metis_client.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
Instance Attribute Details
#bucket_name ⇒ Object
Returns the value of attribute bucket_name
8 9 10 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 8 def bucket_name @bucket_name end |
#filesystem ⇒ Object
Returns the value of attribute filesystem
8 9 10 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 8 def filesystem @filesystem end |
#logger ⇒ Object
Returns the value of attribute logger
8 9 10 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 8 def logger @logger end |
#metis_client ⇒ Object
Returns the value of attribute metis_client
8 9 10 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 8 def metis_client @metis_client end |
#project_name ⇒ Object
Returns the value of attribute project_name
8 9 10 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 8 def project_name @project_name end |
Instance Method Details
#copy_directory(src, dest, root = dest) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 9 def copy_directory(src, dest, root = dest) response = metis_client.list_folder(ListFolderRequest.new(project_name: project_name, bucket_name: bucket_name, folder_path: src)) response.files.all.each do |file| logger&.info("Copying file #{file.file_path} (#{Etna::Formatting.as_size(file.size)})") copy_file(dest: ::File.join(dest, file.file_name), url: file.download_url) end response.folders.all.each do |folder| copy_directory(::File.join(src, folder.folder_name), ::File.join(dest, folder.folder_name), root) end end |
#copy_file(dest:, url:, stub: false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb', line 22 def copy_file(dest:, url:, stub: false) = metis_client.(url) size = [:size] tmp_file = dest upload_timings = [] upload_amount = 0 last_rate = 0.00001 remaining = size filesystem.with_writeable(tmp_file, "w", size_hint: size) do |io| if stub io.write("(stub) #{size} bytes") else metis_client.download_file(url) do |chunk| io.write(chunk) upload_timings << [chunk.length, Time.now.to_f] upload_amount += chunk.length remaining -= chunk.length if upload_timings.length > 150 s, _ = upload_timings.shift upload_amount -= s end _, start_time = upload_timings.first _, end_time = upload_timings.last if start_time == end_time next end rate = upload_amount / (end_time - start_time) if rate / last_rate > 1.3 || rate / last_rate < 0.7 logger&.info("Uploading #{Etna::Formatting.as_size(rate)} per second, #{Etna::Formatting.as_size(remaining)} remaining") if rate == 0 last_rate = 0.0001 else last_rate = rate end end end end end end |