paperclip-azure 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/paperclip/storage/azure.rb +40 -39
- data/paperclip-azure.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a436c5fe249cd01c90a3396d6283eaf8ce193a7
|
4
|
+
data.tar.gz: 8d17a7d45bca35b39619e733a860a5594ced8806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a639a7f4bf18d39940b20a31b1b9ae474d64992b2c800e842a01555506afd52e771e97292112573416533e10fa849be25d65239f3637425b5924e5288e7d8d05
|
7
|
+
data.tar.gz: 7731080268f782451a563dd8fe36b34dfe80ae97e9f875ba3d8df3786ea500808147548e2fc872d31796719e91db112812f6b7eef81d53aad409700dbc9715ce
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
@@ -125,7 +125,28 @@ module Paperclip
|
|
125
125
|
|
126
126
|
unless instances[options]
|
127
127
|
signer = ::Azure::Core::Auth::SharedKey.new options[:storage_account_name], options[:access_key]
|
128
|
-
|
128
|
+
service = ::Azure::BlobService.new(signer, options[:storage_account_name])
|
129
|
+
|
130
|
+
service.filters << ::Azure::Core::Http::RetryPolicy.new do |response, retry_data|
|
131
|
+
status_code = response.status_code == 0 ? 500 : response.status_code
|
132
|
+
@retry_count ||= 0
|
133
|
+
|
134
|
+
if (status_code >= 300 && status_code < 500 && status_code != 408) ||
|
135
|
+
status_code == 501 ||
|
136
|
+
status_code == 505 ||
|
137
|
+
response[:error].description == 'Blob type of the blob reference doesn\'t match blob type of the blob.' ||
|
138
|
+
@retry_count >= 5
|
139
|
+
@retry_count = 0
|
140
|
+
else
|
141
|
+
@retry_count += 1
|
142
|
+
|
143
|
+
sleep ((2**@retry_count) - 1) * 5
|
144
|
+
end
|
145
|
+
|
146
|
+
@retry_count > 0
|
147
|
+
end
|
148
|
+
|
149
|
+
instances[options] = service
|
129
150
|
end
|
130
151
|
|
131
152
|
instances[options]
|
@@ -140,7 +161,7 @@ module Paperclip
|
|
140
161
|
end
|
141
162
|
|
142
163
|
def azure_container
|
143
|
-
@azure_container ||=
|
164
|
+
@azure_container ||= azure_interface.get_container_properties container_name
|
144
165
|
end
|
145
166
|
|
146
167
|
def azure_object(style_name = default_style)
|
@@ -167,7 +188,7 @@ module Paperclip
|
|
167
188
|
end
|
168
189
|
|
169
190
|
def create_container
|
170
|
-
|
191
|
+
azure_interface.create_container container_name
|
171
192
|
end
|
172
193
|
|
173
194
|
def flush_writes #:nodoc:
|
@@ -196,21 +217,19 @@ module Paperclip
|
|
196
217
|
end
|
197
218
|
|
198
219
|
def save_blob(container_name, storage_path, file)
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
blocks << [block_id]
|
210
|
-
end
|
211
|
-
|
212
|
-
azure_interface.commit_blob_blocks container_name, storage_path, blocks
|
220
|
+
if file.size < 64.megabytes
|
221
|
+
azure_interface.create_block_blob container_name, storage_path, file.read
|
222
|
+
else
|
223
|
+
blocks = []; count = 0
|
224
|
+
while data = file.read(4.megabytes)
|
225
|
+
block_id = "block_#{(count += 1).to_s.rjust(5, '0')}"
|
226
|
+
|
227
|
+
azure_interface.create_blob_block container_name, storage_path, block_id, data
|
228
|
+
|
229
|
+
blocks << [block_id]
|
213
230
|
end
|
231
|
+
|
232
|
+
azure_interface.commit_blob_blocks container_name, storage_path, blocks
|
214
233
|
end
|
215
234
|
end
|
216
235
|
|
@@ -219,7 +238,7 @@ module Paperclip
|
|
219
238
|
begin
|
220
239
|
log("deleting #{path}")
|
221
240
|
|
222
|
-
|
241
|
+
azure_interface.delete_blob container_name, path
|
223
242
|
rescue ::Azure::Core::Http::HTTPError => e
|
224
243
|
raise unless e.status_code == 404
|
225
244
|
end
|
@@ -230,12 +249,10 @@ module Paperclip
|
|
230
249
|
def copy_to_local_file(style, local_dest_path)
|
231
250
|
log("copying #{path(style)} to local file #{local_dest_path}")
|
232
251
|
|
233
|
-
|
234
|
-
blob, content = azure_interface.get_blob(container_name, path(style).sub(%r{\A/},''))
|
252
|
+
blob, content = azure_interface.get_blob(container_name, path(style).sub(%r{\A/},''))
|
235
253
|
|
236
|
-
|
237
|
-
|
238
|
-
end
|
254
|
+
::File.open(local_dest_path, 'wb') do |local_file|
|
255
|
+
local_file.write(content)
|
239
256
|
end
|
240
257
|
rescue ::Azure::Core::Http::HTTPError => e
|
241
258
|
raise unless e.status_code == 404
|
@@ -260,22 +277,6 @@ module Paperclip
|
|
260
277
|
raise ArgumentError, "Credentials given are not a path, file, proc, or hash."
|
261
278
|
end
|
262
279
|
end
|
263
|
-
|
264
|
-
def with_azure_error_handling
|
265
|
-
count = 0
|
266
|
-
|
267
|
-
begin
|
268
|
-
yield
|
269
|
-
rescue Exception => e
|
270
|
-
if count <= auto_connect_duration
|
271
|
-
sleep 2** count
|
272
|
-
count += 1
|
273
|
-
retry
|
274
|
-
end
|
275
|
-
|
276
|
-
raise
|
277
|
-
end
|
278
|
-
end
|
279
280
|
end
|
280
281
|
end
|
281
282
|
end
|
data/paperclip-azure.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "paperclip-azure"
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jordan Yaker", "Supportify, Inc."]
|
12
|
-
s.date = "2015-
|
12
|
+
s.date = "2015-02-16"
|
13
13
|
s.description = "An Azure Blob Storage implementation for Paperclip."
|
14
14
|
s.email = "help@supportify.io"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-azure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Yaker
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: azure
|