filbunke 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/filbunke.gemspec +5 -2
- data/lib/filbunke/client.rb +43 -19
- data/lib/filbunke.rb +1 -0
- metadata +18 -4
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ begin
|
|
14
14
|
gem.files.exclude 'pkg'
|
15
15
|
gem.executables = ['filbunked']
|
16
16
|
gem.add_dependency 'json', '>= 1.1.7'
|
17
|
+
gem.add_dependency 'typhoeus', '>= 0.2.0'
|
17
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
19
|
end
|
19
20
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/filbunke.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{filbunke}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Wouter de Bie"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-03}
|
13
13
|
s.default_executable = %q{filbunked}
|
14
14
|
s.description = %q{Filbunke client and library}
|
15
15
|
s.email = %q{wouter@deltaprojects.se}
|
@@ -48,13 +48,16 @@ Gem::Specification.new do |s|
|
|
48
48
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
49
49
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
50
|
s.add_runtime_dependency(%q<json>, [">= 1.1.7"])
|
51
|
+
s.add_runtime_dependency(%q<typhoeus>, [">= 0.2.0"])
|
51
52
|
else
|
52
53
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
54
|
s.add_dependency(%q<json>, [">= 1.1.7"])
|
55
|
+
s.add_dependency(%q<typhoeus>, [">= 0.2.0"])
|
54
56
|
end
|
55
57
|
else
|
56
58
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
59
|
s.add_dependency(%q<json>, [">= 1.1.7"])
|
60
|
+
s.add_dependency(%q<typhoeus>, [">= 0.2.0"])
|
58
61
|
end
|
59
62
|
end
|
60
63
|
|
data/lib/filbunke/client.rb
CHANGED
@@ -26,7 +26,10 @@ module Filbunke
|
|
26
26
|
new_checkpoint = updates["checkpoint"]
|
27
27
|
|
28
28
|
@logger.log "Updating repository: #{repository.name}: #{updated_files.size} files. Checkpoint: #{last_checkpoint} ==> #{new_checkpoint}" if updated_files.size > 0
|
29
|
-
|
29
|
+
|
30
|
+
@hydra = Typhoeus::Hydra.new
|
31
|
+
@async_requests = []
|
32
|
+
|
30
33
|
updated_files.each do |raw_file|
|
31
34
|
file = File.new(raw_file)
|
32
35
|
|
@@ -39,9 +42,7 @@ module Filbunke
|
|
39
42
|
if file_needs_update?(file, local_file_path)
|
40
43
|
|
41
44
|
if update_file!(file, local_file_path) then
|
42
|
-
|
43
|
-
callback.on_update(file)
|
44
|
-
end
|
45
|
+
|
45
46
|
yield file
|
46
47
|
else
|
47
48
|
@logger.log "Unable to get file #{file.url} ==> #{file.path}!"
|
@@ -53,6 +54,10 @@ module Filbunke
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
57
|
+
|
58
|
+
@hydra.run
|
59
|
+
failure = failure || @async_requests.any?{|request| request.handled_response == false }
|
60
|
+
|
56
61
|
failure ? last_checkpoint : (new_checkpoint || last_checkpoint)
|
57
62
|
end
|
58
63
|
|
@@ -120,11 +125,19 @@ module Filbunke
|
|
120
125
|
update_http_file!(file, local_file_path)
|
121
126
|
elsif file.url =~ /^hdfs:\/\//
|
122
127
|
update_hdfs_file!(file, local_file_path)
|
128
|
+
run_callbacks(file)
|
129
|
+
|
123
130
|
else
|
124
131
|
raise "Unsupported protocol for file: #{file.inspect}"
|
125
132
|
end
|
126
133
|
end
|
127
134
|
|
135
|
+
def run_callbacks(file)
|
136
|
+
@callbacks.each do |callback|
|
137
|
+
callback.on_update(file)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
128
141
|
def file_needs_update?(file, local_file_path)
|
129
142
|
return true if file.hash.nil? || file.hash == ""
|
130
143
|
|
@@ -161,26 +174,37 @@ module Filbunke
|
|
161
174
|
end
|
162
175
|
|
163
176
|
def update_http_file!(file, local_file_path)
|
164
|
-
begin
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
+
begin
|
178
|
+
async_request = if @repository.user
|
179
|
+
Typhoeus::Request.new(file.url)
|
180
|
+
else
|
181
|
+
Typhoeus::Request.new(file.url, :user => @repository.user, :password => @repository.pass)
|
182
|
+
end
|
183
|
+
async_request.on_complete do |response|
|
184
|
+
success = true
|
185
|
+
begin
|
186
|
+
if response.code.to_i == 200
|
187
|
+
write_file!(local_file_path, response.body)
|
188
|
+
elsif response.code.to_i == 404
|
189
|
+
delete_file!(local_file_path)
|
190
|
+
else
|
191
|
+
@logger.log "Failed to update file #{file.url}, error code = #{response.code}"
|
192
|
+
success = false
|
193
|
+
end
|
194
|
+
run_callbacks(file) if success
|
195
|
+
rescue StandardError => e
|
196
|
+
@logger.log "Failed to update file #{file.url}: #{e.message}"
|
197
|
+
success = false
|
177
198
|
end
|
178
|
-
|
199
|
+
success
|
179
200
|
end
|
201
|
+
@hydra.queue async_request
|
202
|
+
@async_requests << async_request
|
180
203
|
rescue StandardError => e
|
181
|
-
@logger.log "Failed to update file #{
|
204
|
+
@logger.log "Failed to update file #{file.url}: #{e.message}"
|
182
205
|
return false
|
183
206
|
end
|
207
|
+
return true
|
184
208
|
end
|
185
209
|
|
186
210
|
def update_hdfs_file!(file, local_file_path)
|
data/lib/filbunke.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 1.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 1.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Wouter de Bie
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-03 00:00:00 +01:00
|
18
18
|
default_executable: filbunked
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +43,20 @@ dependencies:
|
|
43
43
|
version: 1.1.7
|
44
44
|
type: :runtime
|
45
45
|
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: typhoeus
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
- 2
|
56
|
+
- 0
|
57
|
+
version: 0.2.0
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
46
60
|
description: Filbunke client and library
|
47
61
|
email: wouter@deltaprojects.se
|
48
62
|
executables:
|