evoker 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/evoker/s3cache.rb +60 -50
- data/lib/evoker/version.rb +1 -1
- metadata +4 -4
data/lib/evoker/s3cache.rb
CHANGED
@@ -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
|
-
|
16
|
-
task :
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
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.
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
65
|
-
|
73
|
+
sh "tar -xzf #{CACHE_TARBALL}"
|
74
|
+
end
|
66
75
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
data/lib/evoker/version.rb
CHANGED
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
18
|
+
date: 2011-04-30 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|