Method: BucketFile#retrieve
- Defined in:
- lib/openc3/utilities/bucket_file_cache.rb
#retrieve(client = @bucket, uncompress = true) ⇒ Object
Returns true if the file was retrieved and added to the disk Returns false if the file already exists Raises an error on retrieval errors
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/openc3/utilities/bucket_file_cache.rb', line 74 def retrieve(client = @bucket, uncompress = true) @mutex.synchronize do local_path = "#{BucketFileCache.instance.cache_dir}/#{File.basename(@bucket_path)}" unless File.exist?(local_path) OpenC3::Logger.debug "Retrieving #{@bucket_path} from logs bucket" retry_count = 0 begin client_result = client.get_object(bucket: ENV['OPENC3_LOGS_BUCKET'], key: @bucket_path, path: local_path) unless File.exist?(local_path) raise "Local file does not exist after get_object: #{client_result.inspect}" end rescue => err # Try to retrieve the file three times retry_count += 1 raise err if retry_count >= 3 OpenC3::Logger.warn("Error retrieving log file from bucket - retry #{retry_count}: #{@bucket_path}\n#{err.formatted}") sleep(1) retry end if File.exist?(local_path) basename = File.basename(local_path) if uncompress and File.extname(basename) == ".gz" uncompressed = OpenC3::BucketUtilities.uncompress_file(local_path) File.delete(local_path) local_path = uncompressed end @size = File.size(local_path) @local_path = local_path return true end end return false end rescue => err @error = err OpenC3::Logger.error "Failed to retrieve #{@bucket_path}\n#{err.formatted}" raise err end |