cnvrg 1.10.17 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29b4ab96b94066d5e799cbd5e648eaae0871a634ac6383a66ca3c82a3af9a038
4
- data.tar.gz: aca3f52a3959cf6db6614bed5b7669c41e9607f0abf25ec83e870783c997f484
3
+ metadata.gz: aa004590a2756120371db2d6322a564e364076453f9d7b858e83c94e2068b4b9
4
+ data.tar.gz: d23ee94fbbd6bfb6b09b303d71f4fa5c646d6fc76cb6d049e96f7d3dddfff348
5
5
  SHA512:
6
- metadata.gz: 96fbd5de39c5aa44d93e24c529b5e149cbd8f689c56329e7c5b4a6f9990d19ca8a7d1fdb1f5f00b8abc05c8dccc061a74de65ac8c81524c27f65b0e349dfdc23
7
- data.tar.gz: 2412c51b6926725be234c022faca6191110caf45de2c83381b171e411f7d7bee78e74d519b91f42e01d07b69413df5df009747f35bd34e480d5733718ccd824c
6
+ metadata.gz: 0f35da8bf64a49b8ddfa3baea029ad08aa29665632763799b550886cc2647aa81933f967ec6bb5b2b41ab536d1784b265b9d139c0151ee92cbee02dcc33e47a0
7
+ data.tar.gz: e355bf1a4081462895a278998010b8ce587d9d4e065a63df3d8cab65948abc09468fb84511e665f29354782dcf94bc9298d701a03592d5daf5503dbb6228afc9
@@ -964,10 +964,9 @@ module Cnvrg
964
964
  Cnvrg::CLI.is_response_success(response,true)
965
965
  dataset_name = response["results"]["name"]
966
966
  dataset_slug = response["results"]["slug"]
967
- dataset_home = Dir.pwd+"/"+dataset_slug
967
+ dataset_home = Dir.pwd + "/" + dataset_slug
968
968
  Dataset.stop_if_dataset_present(dataset_home, dataset_name) if soft
969
969
 
970
- # dataset_home = Dir.pwd
971
970
  if Dataset.blank_clone(owner, dataset_name, dataset_slug)
972
971
  dataset = Dataset.new(dataset_home)
973
972
  log_message("Cloning #{dataset_name}", Thor::Shell::Color::BLUE)
@@ -986,12 +985,13 @@ module Cnvrg
986
985
  begin
987
986
  log_message("Downloading files", Thor::Shell::Color::BLUE)
988
987
  Parallel.map((response["results"]["query_files"]), parallel_options) do |f|
989
- relative_path = f["fullpath"].gsub(/^#{dataset_home}/, "")
988
+ relative_path = f["fullpath"].gsub(/^#{dataset_home}/, "").gsub(/^#{slug}/, "")
990
989
  relative_path_dir = relative_path.split("/")
991
990
  file_name = relative_path_dir.pop()
992
991
  relative_path_dir = relative_path_dir.join("/")
993
992
  abs_path = dataset_home + "/" + relative_path_dir
994
993
  abs_path = dataset_home if flatten
994
+
995
995
  begin
996
996
  FileUtils.mkdir_p(abs_path) unless File.exist? (abs_path + "/" + file_name)
997
997
  rescue
@@ -1781,8 +1781,7 @@ module Cnvrg
1781
1781
  print_table(list)
1782
1782
  end
1783
1783
 
1784
- desc 'commits', 'List all commits for a specific Project'
1785
-
1784
+ desc 'commits', 'List all commits for a specific Project', :hide => true
1786
1785
  def list_commits()
1787
1786
  verify_logged_in(true)
1788
1787
  log_start(__method__, args, options)
@@ -1796,7 +1795,7 @@ module Cnvrg
1796
1795
  end
1797
1796
 
1798
1797
 
1799
- desc 'unlink', 'Unlink a project from current directory'
1798
+ desc 'unlink', 'Unlink a project from current directory', :hide => true
1800
1799
 
1801
1800
  def unlink
1802
1801
  verify_logged_in(false)
@@ -2893,7 +2892,7 @@ module Cnvrg
2893
2892
  end
2894
2893
  end
2895
2894
 
2896
- desc 'show', 'Show specific file from a specific commit'
2895
+ desc 'show', 'Show specific file from a specific commit', :hide => true
2897
2896
  method_option :path, :type => :string, :aliases => ["-p"], :desc => "File path", :default => ""
2898
2897
  method_option :commit, :type => :string, :aliases => ["-c"], :desc => "Commit sha1", :default => nil
2899
2898
 
@@ -4806,8 +4805,7 @@ module Cnvrg
4806
4805
 
4807
4806
  end
4808
4807
 
4809
- desc 'list_machines', 'Lists all machines belong to your organization'
4810
-
4808
+ desc 'list_machines', 'Lists all machines belong to your organization', :hide => true
4811
4809
  def list_machines
4812
4810
  begin
4813
4811
  verify_logged_in(false)
@@ -52,7 +52,7 @@ module Cnvrg
52
52
  end
53
53
  raise SignalException.new(1, "Cant find file #{file}") unless File.exists? "#{Dir.pwd}/#{file}"
54
54
  end
55
- paths.map{|p| p.gsub(/^\.\//, '')}
55
+ paths
56
56
  end
57
57
 
58
58
  def get_files_and_folders(paths)
@@ -316,21 +316,21 @@ module Cnvrg
316
316
  #Cnvrg::Logger.log_method(bind: binding)
317
317
  retry_count += 1
318
318
 
319
- puts "Failed request upload files: #{Time.current}"
320
- puts upload_resp
319
+ Cnvrg::Logger.log_info("Failed request upload files: #{Time.current}, retry: #{retry_count}")
321
320
 
322
- if retry_count > 5
323
- raise Exception.new("Got an error message from server, #{upload_resp.try(:fetch, "message")}")
321
+ if retry_count > 20
322
+ puts "Failed to upload files: #{Time.current}, trying next chunk"
323
+ return nil
324
324
  end
325
325
  sleep 5
326
326
  next
327
327
  end
328
328
  return upload_resp['result'].with_indifferent_access
329
329
  end
330
-
331
330
  end
332
331
 
333
332
  def upload_multiple_files_optimized(files, commit_sha1, threads: 15, chunk_size: 1000, override: false, new_branch: false, prefix: '', partial_commit: nil)
333
+ Thread.report_on_exception = false
334
334
  cli = CLI.new
335
335
  cli.log_message("Using #{threads} threads with chunk size of #{chunk_size}.", Thor::Shell::Color::GREEN)
336
336
 
@@ -342,6 +342,7 @@ module Cnvrg
342
342
  file_queue = Queue.new
343
343
  progress_queue = Queue.new
344
344
  worker_threads = []
345
+ progress_threads = []
345
346
 
346
347
  # Vars to keep track of uploaded files and directories
347
348
  dirs = []
@@ -359,56 +360,82 @@ module Cnvrg
359
360
  cli.log_message("Error while uploading file: #{file[:absolute_path]}", Thor::Shell::Color::RED)
360
361
  Cnvrg::Logger.log_error_message("Error while upload single file #{file["path"]}")
361
362
  end
363
+ while progress_queue.size > 15000
364
+ sleep(0.1)
365
+ end
362
366
  progress_queue << file
363
367
  end
364
368
  end
365
369
  end
366
370
 
367
371
  # init the thread that handles the file upload progress and saving them in the server
368
- progress_thread = Thread.new do
369
- loop do
370
- file = progress_queue.deq(non_block: true) rescue nil # to prevent deadlocks
371
- unless file.nil?
372
- progress_mutex.synchronize {
373
- progressbar.progress += 1
374
- uploaded_files.append(file) if file[:success]
375
- }
376
-
377
- if uploaded_files.size == chunk_size or progressbar.finished?
378
- refresh_storage_token
379
- Cnvrg::Logger.info("Finished upload chunk of #{chunk_size} files")
380
- Cnvrg::Logger.info("Sending Upload files save")
381
- blob_ids = uploaded_files.map {|f| f['bv_id']}
382
- Cnvrg::Logger.info("Sending chunk to server")
383
- upload_resp = Cnvrg::API.request(@base_resource + "upload_files_save", "POST", {commit: commit_sha1, blob_ids: blob_ids, dirs: dirs})
384
- unless Cnvrg::CLI.is_response_success(upload_resp, false)
385
- Cnvrg::Logger.log_method(bind: binding)
386
- raise Exception.new("Got an error message from server, #{upload_resp.try(:fetch, "message")}")
372
+ threads.times do |i|
373
+ progress_threads[i] = Thread.new do
374
+ loop do
375
+ file = progress_queue.deq(non_block: true) rescue nil # to prevent deadlocks
376
+ unless file.nil?
377
+ blob_ids = []
378
+ dirs_to_upload = []
379
+
380
+ progress_mutex.synchronize {
381
+ progressbar.progress += 1
382
+ uploaded_files.append(file) if file[:success]
383
+
384
+ if uploaded_files.size >= chunk_size or progressbar.finished?
385
+ blob_ids = uploaded_files.map {|f| f['bv_id']}
386
+ dirs_to_upload = dirs.clone
387
+ uploaded_files = []
388
+ dirs = []
389
+ end
390
+ }
391
+
392
+ if blob_ids.present?
393
+ refresh_storage_token
394
+ Cnvrg::Logger.info("Finished upload chunk of #{chunk_size} files, Sending Upload files save")
395
+
396
+
397
+ retry_count = 0
398
+ loop do
399
+ upload_resp = Cnvrg::API.request(@base_resource + "upload_files_save", "POST", {commit: commit_sha1, blob_ids: blob_ids, dirs: dirs_to_upload})
400
+
401
+ if not (Cnvrg::CLI.is_response_success(upload_resp, false))
402
+ retry_count += 1
403
+ Cnvrg::Logger.log_error_message("Failed request save files: #{Time.current}, retry: #{retry_count}")
404
+ Cnvrg::Logger.info("Got an error message from server, #{upload_resp.try(:fetch, "message")}")
405
+ if retry_count > 20
406
+ puts "Failed to save files: #{Time.current}, trying next chunk"
407
+ break
408
+ end
409
+ sleep 5
410
+ next
411
+ end
412
+ Cnvrg::Logger.info("Chunk saved on server")
413
+ break
414
+ end
387
415
  end
388
- Cnvrg::Logger.info("Chunk saved on server")
389
- uploaded_files = []
390
- dirs = []
416
+ else
417
+ sleep(0.1)
391
418
  end
392
- else
393
- sleep(0.1)
394
- end
395
419
 
396
- if progressbar.finished?
397
- Cnvrg::Logger.info("Progress bar finished closing queues")
398
- file_queue.close()
399
- progress_queue.close()
400
- Thread.exit
420
+ if progressbar.finished?
421
+ Cnvrg::Logger.info("Progress bar finished closing queues")
422
+ file_queue.close()
423
+ progress_queue.close()
424
+ Thread.exit
425
+ end
401
426
  end
402
427
  end
403
428
  end
404
429
 
405
430
  file_chunks = files.each_slice(chunk_size).to_a
406
431
  # Fetch the required files from the server:
407
- Parallel.map((file_chunks), in_threads: 10) do |files_chunk|
432
+ Parallel.map((file_chunks), in_threads: threads) do |chunk|
433
+ files_chunk = chunk.map{|p| p.gsub(/^\.\//, '')}
408
434
  Cnvrg::Logger.info("Generating chunk idx")
409
- tree = @dataset.generate_chunked_idx(files_chunk, prefix: prefix, threads: threads)
435
+ tree = @dataset.generate_chunked_idx(files_chunk, prefix: prefix, threads: threads, cli: cli)
410
436
  Cnvrg::Logger.info("Getting files info from server")
411
437
  results = request_upload_files(commit_sha1, tree, override, new_branch, partial_commit)
438
+ next unless results
412
439
 
413
440
  if results['files'].blank?
414
441
  progress_mutex.synchronize { progressbar.progress += tree.keys.length }
@@ -431,12 +458,11 @@ module Cnvrg
431
458
  file_queue.push tree[key].merge(files_to_upload[key])
432
459
  end
433
460
  end
434
- Cnvrg::Logger.info("Finishing sub processes of datasets' upload")
435
- progress_thread.join()
461
+ Cnvrg::Logger.info("Waiting to progress and workers to finish")
462
+ progress_threads.each(&:join)
436
463
  worker_threads.each(&:join)
437
-
464
+ Thread.report_on_exception = true
438
465
  rescue => e
439
- puts e
440
466
  Cnvrg::Logger.log_method(bind: binding)
441
467
  Cnvrg::Logger.log_error(e)
442
468
  raise e
@@ -500,7 +526,7 @@ module Cnvrg
500
526
  upload_resp = Cnvrg::API.request(@base_resource + "upload_file", 'POST_FILE', {absolute_path: absolute_path, relative_path: relative_path,
501
527
  commit_sha1: commit_sha1, file_name: file_name,
502
528
  file_size: file_size, file_content_type: content_type, sha1: sha1})
503
- puts upload_resp
529
+
504
530
 
505
531
  end
506
532
 
@@ -547,7 +573,7 @@ module Cnvrg
547
573
  return false
548
574
  end
549
575
  rescue => e
550
- puts e.message
576
+ #puts e.message
551
577
  return false
552
578
  end
553
579
  end
@@ -792,7 +818,7 @@ module Cnvrg
792
818
  return resp
793
819
 
794
820
  rescue => e
795
- puts e.message
821
+ #puts e.message
796
822
  return false
797
823
 
798
824
  end
@@ -1174,7 +1200,9 @@ module Cnvrg
1174
1200
  end
1175
1201
 
1176
1202
  def end_commit(commit_sha1, force, success: true, uploaded_files: 0, commit_type: nil)
1203
+ counter = 0
1177
1204
  begin
1205
+ counter += 1
1178
1206
  response = Cnvrg::API.request(
1179
1207
  "#{base_resource}/commit/end",
1180
1208
  'POST',
@@ -1186,9 +1214,11 @@ module Cnvrg
1186
1214
  commit_type: commit_type
1187
1215
  }
1188
1216
  )
1189
- Cnvrg::CLI.is_response_success(response, true)
1217
+ is_success = Cnvrg::CLI.is_response_success(response, false)
1218
+ raise Exception.new("Invalid response #{response}") unless is_success
1190
1219
  return response
1191
1220
  rescue => e
1221
+ retry if counter <= 20
1192
1222
  return false
1193
1223
  end
1194
1224
  end
@@ -541,7 +541,7 @@ module Cnvrg
541
541
  "#{url}/#{self.owner}/datasets/#{self.slug}"
542
542
  end
543
543
 
544
- def generate_chunked_idx(list_files = [], threads: 15, prefix: '')
544
+ def generate_chunked_idx(list_files = [], threads: 15, prefix: '', cli: nil)
545
545
  tree = {}
546
546
  Parallel.map(list_files, in_threads: threads) do |file|
547
547
 
@@ -552,12 +552,21 @@ module Cnvrg
552
552
  label = safe_path.gsub(self.local_path + "/", "")
553
553
  label = "#{prefix}/#{label}" if prefix.present?
554
554
  if not Cnvrg::Files.valid_file_name?(label)
555
- raise StandardError.new("#{label} is not a valid file name.")
555
+ if cli
556
+ cli.log_message("#{label} is not a valid file name, skipping it", Thor::Shell::Color::RED)
557
+ else
558
+ puts "#{label} is not a valid file name, , skipping it"
559
+ end
556
560
  end
557
561
  if File.directory? file
558
562
  tree[label + "/"] = nil
559
563
  else
560
- sha1 = OpenSSL::Digest::SHA1.file(file).hexdigest
564
+ begin
565
+ sha1 = OpenSSL::Digest::SHA1.file(file).hexdigest
566
+ rescue => e
567
+ #puts "Could'nt calculate sha1 for: #{file}, Error: #{e.message}"
568
+ next
569
+ end
561
570
  file_name = File.basename file
562
571
  file_size = File.size(file).to_f
563
572
  mime_type = MimeMagic.by_path(file)
@@ -14,8 +14,15 @@ module Cnvrg
14
14
  end
15
15
 
16
16
  def extract_key_iv(sts_path)
17
- sts = open(sts_path).read rescue nil
18
- raise StandardError.new("Cant open sts") if sts.blank?
17
+ count = 20
18
+ begin
19
+ count += 1
20
+ sts = open(sts_path, {ssl_verify_mode: 0}).read rescue nil
21
+ rescue => e
22
+ Cnvrg::Logger.log_error(e)
23
+ retry if count <= 20
24
+ raise StandardError.new("Cant access storage: #{e.message}")
25
+ end
19
26
  sts.split("\n")
20
27
  end
21
28
 
@@ -1,3 +1,3 @@
1
1
  module Cnvrg
2
- VERSION = '1.10.17'
2
+ VERSION = '1.11.1'
3
3
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnvrg
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.17
4
+ version: 1.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yochay Ettun
8
8
  - Leah Kolben
9
9
  - Omer Shacham
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-09-15 00:00:00.000000000 Z
13
+ date: 2020-10-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -438,7 +438,7 @@ files:
438
438
  homepage: https://cnvrg.io
439
439
  licenses: []
440
440
  metadata: {}
441
- post_install_message:
441
+ post_install_message:
442
442
  rdoc_options: []
443
443
  require_paths:
444
444
  - lib
@@ -454,7 +454,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
454
454
  version: '0'
455
455
  requirements: []
456
456
  rubygems_version: 3.1.2
457
- signing_key:
457
+ signing_key:
458
458
  specification_version: 4
459
459
  summary: A CLI tool for interacting with cnvrg.io.
460
460
  test_files: []