Class: S3FileCollection
Instance Method Summary collapse
- #add(s3_path, size, priority) ⇒ Object
- #current_disk_usage ⇒ Object
- #get(local_path) ⇒ Object
- #get_next_to_retrieve ⇒ Object
-
#initialize ⇒ S3FileCollection
constructor
A new instance of S3FileCollection.
- #length ⇒ Object
Constructor Details
#initialize ⇒ S3FileCollection
Returns a new instance of S3FileCollection.
88 89 90 91 |
# File 'lib/openc3/utilities/s3_file_cache.rb', line 88 def initialize @array = [] @mutex = Mutex.new end |
Instance Method Details
#add(s3_path, size, priority) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/openc3/utilities/s3_file_cache.rb', line 93 def add(s3_path, size, priority) @mutex.synchronize do @array.each do |file| if file.s3_path == s3_path file.priority = priority if priority < file.priority @array.sort! {|a,b| a.priority <=> b.priority} return file end end file = S3File.new(s3_path, size, priority) @array << file @array.sort! {|a,b| a.priority <=> b.priority} return file end end |
#current_disk_usage ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/openc3/utilities/s3_file_cache.rb', line 131 def current_disk_usage @mutex.synchronize do total_size = 0 @array.each do |file| total_size += file.size if file.local_path end return total_size end end |
#get(local_path) ⇒ Object
113 114 115 116 117 118 119 120 |
# File 'lib/openc3/utilities/s3_file_cache.rb', line 113 def get(local_path) @mutex.synchronize do @array.each do |file| return file if file.local_path == local_path end end return nil end |
#get_next_to_retrieve ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/openc3/utilities/s3_file_cache.rb', line 122 def get_next_to_retrieve @mutex.synchronize do @array.each do |file| return file unless file.local_path end end return nil end |
#length ⇒ Object
109 110 111 |
# File 'lib/openc3/utilities/s3_file_cache.rb', line 109 def length @array.length end |