cnvrg 1.10.16 → 1.11

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: 5db0dade8678ab44aff68dbe2869601f2d328099cbf9206c8bd321380e3f2f27
4
- data.tar.gz: 0571504e35f30357bca6a1b0aea9224602a9ff8bde6c4a5191bacb5e34bcb886
3
+ metadata.gz: 04a9acd0283e8ef3c4aacfa23c90d2954e3e0a2ad4f2a70eed66ea0b87144956
4
+ data.tar.gz: 8221939940f215d62f6c5a66705cbdd20f6218c87007d2f71d9a4fdba0af5285
5
5
  SHA512:
6
- metadata.gz: 69dc6323bfeb7639a7ff729b974c0e485566b975ad0356e31aaaf690e32ce08ac4518b0c7dee3ec4cb6d013009e928ba51679d3d4296a0505b46506c822f2fc0
7
- data.tar.gz: a030f21f9ded5523f7b606c7b01d38b949b5c4036474de017c37d40727efade68113672c80e5c8bcb8dc7138a0593435af9bd6efddf4b09c063fcd838bbcb9f3
6
+ metadata.gz: 286544fb7129aef8fa679aa3daacdfa983cc10154709ceadbaf58406676780225559702b41195182156a379e0f4c6bc192d067eb39a7476a605bd9381f504597
7
+ data.tar.gz: '09e9a6a66e91b29afd2940b02d424785556cce005d1b966e7f3e82c6eb448014d6c8657570c4305274fae7b1d34f824520f6e12a90688f069dfaa8facad5d1b8'
@@ -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
 
@@ -11,7 +11,7 @@ module Cnvrg
11
11
  @tempfile = nil
12
12
  @bucket_name = Cnvrg::Helpers.decrypt(@key, @iv, bucket_name)
13
13
  init_gcp_credentials
14
- @storage = Google::Cloud::Storage.new(project_id: @project_id, credentials: @credentials, retries: 20)
14
+ @storage = Google::Cloud::Storage.new(project_id: @project_id, credentials: @credentials, retries: 50, timeout: 43200)
15
15
  @bucket = @storage.bucket(@bucket_name)
16
16
  @bucket.name
17
17
  rescue => e
@@ -47,4 +47,4 @@ module Cnvrg
47
47
  end
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Cnvrg
2
- VERSION = '1.10.16'
2
+ VERSION = '1.11'
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.16
4
+ version: '1.11'
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-13 00:00:00.000000000 Z
13
+ date: 2020-09-23 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
@@ -453,8 +453,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
453
453
  - !ruby/object:Gem::Version
454
454
  version: '0'
455
455
  requirements: []
456
- rubygems_version: 3.1.2
457
- signing_key:
456
+ rubygems_version: 3.0.4
457
+ signing_key:
458
458
  specification_version: 4
459
459
  summary: A CLI tool for interacting with cnvrg.io.
460
460
  test_files: []