evoker 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ # Caching of downloaded upstream stuff as a tarball in an S3 bucket.
2
+
3
+ require 'evoker'
4
+ require 'fog'
5
+
6
+ module Evoker
7
+ def _get_bucket
8
+ $s3 ||= Fog::Storage.new(
9
+ :provider => "AWS",
10
+ :aws_access_key_id => CACHE_S3_ACCESS_KEY_ID,
11
+ :aws_secret_access_key => CACHE_S3_SECRET_ACCESS_KEY)
12
+ $bucket ||= $s3.directories.get(CACHE_S3_BUCKET)
13
+ end
14
+
15
+ desc "Store all downloaded entities in an S3 bucket"
16
+ task :cache => ENTITIES do
17
+ bucket = _get_bucket
18
+
19
+ if tarball = bucket.files.get(CACHE_TARBALL)
20
+ if ENV['FORCE']
21
+ puts "INFO: deleting file #{CACHE_TARBALL} from bucket because FORCE"
22
+ tarball.destroy
23
+ bucket.reload
24
+ else
25
+ raise "ERROR: file #{CACHE_TARBALL} already in the bucket."
26
+ end
27
+ end
28
+ sh "tar -czf #{CACHE_TARBALL} --exclude '#{CACHE_BASENAME}*.tgz' ."
29
+ puts "INFO: uploading #{CACHE_TARBALL} to #{CACHE_S3_BUCKET}..."
30
+ File.open(CACHE_TARBALL, 'r') do |tarball|
31
+ bucket.files.create(
32
+ :key => CACHE_TARBALL,
33
+ :body => tarball)
34
+ end
35
+ end
36
+
37
+ desc "Download pre-cached entities from an S3 bucket"
38
+ task :uncache do
39
+ wait = ENV['WAIT'] ? ENV['WAIT'].to_i : 60*45
40
+ bucket = _get_bucket
41
+
42
+ if wait > 0
43
+ print "Waiting for #{CACHE_TARBALL} .."
44
+ STDOUT.flush
45
+ bucket.wait_for(wait) {
46
+ print '.'
47
+ STDOUT.flush
48
+ bucket.files.find { |f| f.key == CACHE_TARBALL }
49
+ } or raise "Timed out waiting for #{CACHE_TARBALL}"
50
+ puts " got it."
51
+ end
52
+
53
+ print "Downloading #{CACHE_TARBALL} .."
54
+ STDOUT.flush
55
+ File.open(CACHE_TARBALL, 'w') { |tarball_file|
56
+ bucket.files.get(CACHE_TARBALL) { |tarball_contents, _, _|
57
+ print '.'
58
+ STDOUT.flush
59
+ tarball_file.write(tarball_contents)
60
+ }
61
+ }
62
+ puts " got it."
63
+
64
+ sh "tar -xvf #{CACHE_TARBALL}"
65
+ end
66
+
67
+ desc "Download pre-cached entities from an S3 bucket if available; download normally and cache if not available."
68
+ task :uncache_or_cache do
69
+ bucket = _get_bucket
70
+ if bucket.files.find { |f| f.key == CACHE_TARBALL }
71
+ Rake::Task[:uncache].execute
72
+ else
73
+ Rake::Task[:cache].execute
74
+ end
75
+ end
76
+ end
@@ -2,7 +2,7 @@ module Evoker
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
 
8
8
  def VERSION.require_version(major, minor=0, tiny=0)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evoker
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Maciej Pasternacki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-25 00:00:00 +02:00
18
+ date: 2011-04-29 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,7 @@ extra_rdoc_files: []
45
45
 
46
46
  files:
47
47
  - lib/evoker/python.rb
48
+ - lib/evoker/s3cache.rb
48
49
  - lib/evoker/version.rb
49
50
  - lib/evoker.rb
50
51
  - LICENSE