Class: Omnibus::S3Cache
- Inherits:
-
Object
- Object
- Omnibus::S3Cache
- Extended by:
- Digestable, S3Helpers
- Includes:
- Logging
- Defined in:
- lib/omnibus/s3_cache.rb
Class Method Summary collapse
-
.fetch_missing ⇒ true
Fetch all source tarballs onto the local machine.
-
.key_for(software) ⇒ String
The key with which to cache the package on S3.
-
.keys ⇒ Array<String>
The list of objects in the cache, by their key.
-
.list ⇒ Array<Software>
List all software in the cache.
-
.missing ⇒ Array<Software>
List all software missing from the cache.
-
.populate ⇒ true
Populate the cache with the all the missing software definitions.
- .url_for(software) ⇒ Object
Methods included from S3Helpers
Methods included from Digestable
digest, digest_directory, included
Methods included from Logging
Class Method Details
.fetch_missing ⇒ true
Fetch all source tarballs onto the local machine.
98 99 100 101 102 103 104 |
# File 'lib/omnibus/s3_cache.rb', line 98 def fetch_missing missing.each do |software| without_caching do software.fetch end end end |
.key_for(software) ⇒ String
The key with which to cache the package on S3. This is the name of the package, the version of the package, and its md5 checksum.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/omnibus/s3_cache.rb', line 119 def key_for(software) unless software.name raise InsufficientSpecification.new(:name, software) end unless software.version raise InsufficientSpecification.new(:version, software) end unless software.fetcher.checksum raise InsufficientSpecification.new("source md5 checksum", software) end "#{software.name}-#{software.version}-#{software.fetcher.checksum}" end |
.keys ⇒ Array<String>
The list of objects in the cache, by their key.
45 46 47 |
# File 'lib/omnibus/s3_cache.rb', line 45 def keys bucket.objects.map(&:key) end |
.list ⇒ Array<Software>
List all software in the cache.
32 33 34 35 36 37 38 |
# File 'lib/omnibus/s3_cache.rb', line 32 def list cached = keys softwares.select do |software| key = key_for(software) cached.include?(key) end end |
.missing ⇒ Array<Software>
List all software missing from the cache.
54 55 56 57 58 59 60 |
# File 'lib/omnibus/s3_cache.rb', line 54 def missing cached = keys softwares.select do |software| key = key_for(software) !cached.include?(key) end end |
.populate ⇒ true
Populate the cache with the all the missing software definitions.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/omnibus/s3_cache.rb', line 67 def populate missing.each do |software| without_caching do software.fetch end key = key_for(software) fetcher = software.fetcher log.info(log_key) do "Caching '#{fetcher.downloaded_file}' to '#{Config.s3_bucket}/#{key}'" end # Fetcher has already verified the downloaded file in software.fetch. # Compute the md5 from scratch because the fetcher may have been # specified with a different hashing algorithm. md5 = digest(fetcher.downloaded_file, :md5) File.open(fetcher.downloaded_file, "rb") do |file| store_object(key, file, md5, "public-read") end end true end |