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.
86 87 88 89 |
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 86 def initialize @array = [] @mutex = Mutex.new end |
Instance Method Details
#add(s3_path, size, priority) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 91 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
129 130 131 132 133 134 135 136 137 |
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 129 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
111 112 113 114 115 116 117 118 |
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 111 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
120 121 122 123 124 125 126 127 |
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 120 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
107 108 109 |
# File 'lib/cosmos/utilities/s3_file_cache.rb', line 107 def length @array.length end |