evoker 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,75 +2,85 @@
2
2
 
3
3
  require 'evoker'
4
4
  require 'fog'
5
+ require 'rake/clean'
5
6
 
6
7
  module Evoker
7
8
  def _get_bucket
8
9
  $s3 ||= Fog::Storage.new(
9
10
  :provider => "AWS",
10
11
  :aws_access_key_id => CACHE_S3_ACCESS_KEY_ID,
11
- :aws_secret_access_key => CACHE_S3_SECRET_ACCESS_KEY)
12
+ :aws_secret_access_key => CACHE_S3_SECRET_ACCESS_KEY,
13
+ :persistent => false)
12
14
  $bucket ||= $s3.directories.get(CACHE_S3_BUCKET)
13
15
  end
14
16
 
15
- desc "Store all downloaded entities in an S3 bucket"
16
- task :cache => ENTITIES do
17
- bucket = _get_bucket
17
+ # hack to add cached tarballs to clobber before we know cache basename
18
+ task :_s3cache_clobber_tarball do
19
+ CLOBBER.add("#{CACHE_BASENAME}*.tgz")
20
+ end
21
+ task :clobber => :_s3cache_clobber_tarball
18
22
 
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."
23
+ namespace :s3cache do
24
+ desc "Pack current directory and store resulting tarball in an S3 bucket"
25
+ task :upload do
26
+ bucket = _get_bucket
27
+
28
+ if tarball = bucket.files.get(CACHE_TARBALL)
29
+ if ENV['FORCE']
30
+ puts "INFO: deleting file #{CACHE_TARBALL} from bucket because FORCE"
31
+ tarball.destroy
32
+ bucket.reload
33
+ else
34
+ raise "ERROR: file #{CACHE_TARBALL} already in the bucket."
35
+ end
36
+ end
37
+ sh "tar -czf #{CACHE_TARBALL} --exclude '#{CACHE_BASENAME}*.tgz' ."
38
+ puts "INFO: uploading #{CACHE_TARBALL} to #{CACHE_S3_BUCKET}..."
39
+ File.open(CACHE_TARBALL, 'r') do |tarball|
40
+ bucket.files.create(
41
+ :key => CACHE_TARBALL,
42
+ :body => tarball)
26
43
  end
27
44
  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
45
 
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
46
+ desc "Download pre-cached entities from an S3 bucket"
47
+ task :download do
48
+ wait = ENV['WAIT'] ? ENV['WAIT'].to_i : 60*45
49
+ bucket = _get_bucket
41
50
 
42
- if wait > 0
43
- print "Waiting for #{CACHE_TARBALL} .."
44
- STDOUT.flush
45
- bucket.wait_for(wait) {
46
- print '.'
51
+ if wait > 0
52
+ print "Waiting for #{CACHE_TARBALL} .."
47
53
  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
54
+ bucket.wait_for(wait) {
55
+ print '.'
56
+ STDOUT.flush
57
+ bucket.files.find { |f| f.key == CACHE_TARBALL }
58
+ } or raise "Timed out waiting for #{CACHE_TARBALL}"
59
+ puts " got it."
60
+ end
52
61
 
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)
62
+ print "Downloading #{CACHE_TARBALL} .."
63
+ STDOUT.flush
64
+ File.open(CACHE_TARBALL, 'w') { |tarball_file|
65
+ bucket.files.get(CACHE_TARBALL) { |tarball_contents, _, _|
66
+ print '.'
67
+ STDOUT.flush
68
+ tarball_file.write(tarball_contents)
69
+ }
60
70
  }
61
- }
62
- puts " got it."
71
+ puts " got it."
63
72
 
64
- sh "tar -xvf #{CACHE_TARBALL}"
65
- end
73
+ sh "tar -xzf #{CACHE_TARBALL}"
74
+ end
66
75
 
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
76
+ desc "Download pre-cached entities from an S3 bucket if available; download normally and cache if not available."
77
+ task :download_or_upload do
78
+ bucket = _get_bucket
79
+ if bucket.files.find { |f| f.key == CACHE_TARBALL }
80
+ Rake::Task["s3cache:download"].invoke
81
+ else
82
+ Rake::Task["s3cache:upload"].invoke
83
+ end
74
84
  end
75
85
  end
76
86
  end
@@ -2,7 +2,7 @@ module Evoker
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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-29 00:00:00 +02:00
18
+ date: 2011-04-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency