attache 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/attache/download.rb +21 -30
- data/lib/attache/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 637b0e3db30b5d851946c433e8df383d38708d39
|
4
|
+
data.tar.gz: 9103c50678a077092a9c43a10bab435e425e86ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca9c7794c0dac8a080ec267d849c3d0a786fb1b60c3041b80548c37115ac2af33d57963d29f2c4634aa23647252ce5eaa9561b4a63b52b068033f82200a41eb1
|
7
|
+
data.tar.gz: 980b910c931c32d814d7c757fe7e74a0b1ee376a4e657c988ab531866f52e2029279b0961fe24c6b08423b43ef915d912aff9666048cbf78dd1f7894c7500d7b
|
data/README.md
CHANGED
data/lib/attache/download.rb
CHANGED
@@ -27,19 +27,18 @@ class Attache::Download < Attache::Base
|
|
27
27
|
file = begin
|
28
28
|
cachekey = File.join(request_hostname(env), relpath)
|
29
29
|
Attache.cache.fetch(cachekey) do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
Attache.logger.info "[POOL] not found #{k} #{relpath}"
|
37
|
-
nil
|
30
|
+
name_with_vhost_pairs = vhosts.inject({}) { |sum,(k,v)| (v ? sum.merge(k => v) : sum) }
|
31
|
+
get_first_result_present_async(name_with_vhost_pairs.collect {|name, vhost|
|
32
|
+
lambda { Thread.handle_interrupt(BasicObject => :on_blocking) {
|
33
|
+
begin
|
34
|
+
vhost.storage_get(relpath: relpath).tap do |v|
|
35
|
+
Attache.logger.info "[POOL] found #{name} #{relpath} = #{v.inspect}"
|
38
36
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
rescue Exception
|
38
|
+
Attache.logger.info "[POOL] not found #{name} #{relpath}"
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
} }
|
43
42
|
})
|
44
43
|
end
|
45
44
|
rescue Exception # Errno::ECONNREFUSED, OpenURI::HTTPError, Excon::Errors, Fog::Errors::Error
|
@@ -93,24 +92,16 @@ class Attache::Download < Attache::Base
|
|
93
92
|
end
|
94
93
|
end
|
95
94
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
Attache.logger.info "[POOL] found #{name.inspect}"
|
107
|
-
else
|
108
|
-
# no contribution
|
109
|
-
end
|
110
|
-
}
|
111
|
-
end
|
112
|
-
}
|
113
|
-
threads.each(&:join)
|
95
|
+
# Ref https://gist.github.com/sferik/39831f34eb87686b639c#gistcomment-1652888
|
96
|
+
# a bit more complicated because we *want* to ignore falsey result
|
97
|
+
def get_first_result_present_async(lambdas)
|
98
|
+
return if lambdas.empty? # queue.pop will never happen
|
99
|
+
queue = Queue.new
|
100
|
+
threads = lambdas.collect { |code| Thread.new { queue << code.call } }
|
101
|
+
until result = queue.pop do
|
102
|
+
break unless threads.any?(&:alive?) || queue.size > 0
|
103
|
+
end
|
104
|
+
threads.each(&:kill)
|
114
105
|
result
|
115
106
|
end
|
116
107
|
end
|
data/lib/attache/version.rb
CHANGED