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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8285df5718393e0e9cda5f0cfd3465eb49cd2347
4
- data.tar.gz: 74a802a4572dbaab662b6d1bebaf5cdf750ebfce
3
+ metadata.gz: 6a436c5fe249cd01c90a3396d6283eaf8ce193a7
4
+ data.tar.gz: 8d17a7d45bca35b39619e733a860a5594ced8806
5
5
  SHA512:
6
- metadata.gz: 03e5de1b225b119b900d3d64cac609bfc84859a597cb1cb710690bfb36a1b27ea0219172e7910fe539fca5cbb03c1ab417e8c6e77177b31cd56f0e6d45a6ea82
7
- data.tar.gz: 9233945f21ebd52697428d7b472c40b13c02250569c11cb29833901235a8f68fe4e6e4f1c8dff19c763eaafef76af63309ccdb936b5dcf3e10c372c3a21b1bf8
6
+ metadata.gz: a639a7f4bf18d39940b20a31b1b9ae474d64992b2c800e842a01555506afd52e771e97292112573416533e10fa849be25d65239f3637425b5924e5288e7d8d05
7
+ data.tar.gz: 7731080268f782451a563dd8fe36b34dfe80ae97e9f875ba3d8df3786ea500808147548e2fc872d31796719e91db112812f6b7eef81d53aad409700dbc9715ce
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
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
- instances[options] = ::Azure::BlobService.new(signer, options[:storage_account_name])
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 ||= with_azure_error_handling { azure_interface.get_container_properties container_name }
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
- with_azure_error_handling { azure_interface.create_container container_name }
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
- with_azure_error_handling do
200
- if file.size < 64.megabytes
201
- azure_interface.create_block_blob container_name, storage_path, file.read
202
- else
203
- blocks = []; count = 0
204
- while data = file.read(4.megabytes)
205
- block_id = "block_#{(count += 1).to_s.rjust(5, '0')}"
206
-
207
- azure_interface.create_blob_block container_name, storage_path, block_id, data
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
- with_azure_error_handling { azure_interface.delete_blob container_name, path }
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
- with_azure_error_handling do
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
- ::File.open(local_dest_path, 'wb') do |local_file|
237
- local_file.write(content)
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
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "paperclip-azure"
8
- s.version = "0.2.3"
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-01-29"
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.3
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-01-29 00:00:00.000000000 Z
12
+ date: 2015-02-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: azure