Class: Omnibus::S3Cache

Inherits:
Object
  • Object
show all
Extended by:
S3Helpers
Includes:
Logging
Defined in:
lib/omnibus/s3_cache.rb

Class Method Summary collapse

Methods included from S3Helpers

included

Methods included from Logging

included

Class Method Details

.fetch_missingtrue

Fetch all source tarballs onto the local machine.

Returns:

  • (true)


92
93
94
95
96
97
98
# File 'lib/omnibus/s3_cache.rb', line 92

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 checksum.

Examples:

"zlib-1.2.6-618e944d7c7cd6521551e30b32322f4a"

Parameters:

Returns:

  • (String)


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/omnibus/s3_cache.rb', line 113

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

.keysArray<String>

The list of objects in the cache, by their key.

Returns:

  • (Array<String>)


44
45
46
# File 'lib/omnibus/s3_cache.rb', line 44

def keys
  bucket.objects.map(&:key)
end

.listArray<Software>

List all software in the cache.

Returns:



31
32
33
34
35
36
37
# File 'lib/omnibus/s3_cache.rb', line 31

def list
  cached = keys
  softwares.select do |software|
    key = key_for(software)
    cached.include?(key)
  end
end

.missingArray<Software>

List all software missing from the cache.

Returns:



53
54
55
56
57
58
59
# File 'lib/omnibus/s3_cache.rb', line 53

def missing
  cached = keys
  softwares.select do |software|
    key = key_for(software)
    !cached.include?(key)
  end
end

.populatetrue

Populate the cache with the all the missing software definitions.

Returns:

  • (true)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/omnibus/s3_cache.rb', line 66

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

    File.open(fetcher.downloaded_file, 'rb') do |file|
      store_object(key, file, software.fetcher.checksum, 'public-read')
    end
  end

  true
end