super_queue 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/super_queue.rb +29 -15
  2. metadata +1 -1
data/lib/super_queue.rb CHANGED
@@ -138,9 +138,12 @@ class SuperQueue
138
138
  def initialize_sqs(opts)
139
139
  create_sqs_connection(opts)
140
140
  create_sqs_queue(opts)
141
- check_for_queue_creation_success
142
- @sqs.set_queue_attributes(q_url, "VisibilityTimeout", opts[:visibility_timeout]) if opts[:visibility_timeout]
143
- @request_count += 1
141
+ if opts[:replace_existing_queue] && (sqs_length > 0)
142
+ delete_queue
143
+ puts "Waiting 60s to create new queue..."
144
+ sleep 62 # You must wait 60s after deleting a q to create one with the same name
145
+ create_sqs_queue(opts)
146
+ end
144
147
  end
145
148
 
146
149
  def create_sqs_connection(opts)
@@ -156,18 +159,23 @@ class SuperQueue
156
159
  end
157
160
 
158
161
  def create_sqs_queue(opts)
159
- @sqs_queue = @sqs.create_queue(queue_name)
160
- if opts[:replace_existing_queue] && (sqs_length > 0)
161
- delete_queue
162
- puts "Waiting 60s to create new queue..."
163
- sleep 62 # You must wait 60s after deleting a q to create one with the same name
164
- if opts[:visibility_timeout]
165
- @sqs_queue = @sqs.create_queue(queue_name, {"DefaultVisibilityTimeout" => opts[:visibility_timeout]})
166
- else
167
- @sqs_queue = @sqs.create_queue(queue_name)
168
- end
162
+ retries = 0
163
+ begin
164
+ @sqs_queue = new_sqs_queue(opts)
165
+ check_for_queue_creation_success
166
+ rescue RuntimeError => e
167
+ retries += 1
168
+ (retries >= 10) ? retry : raise(e)
169
169
  end
170
+ end
171
+
172
+ def new_sqs_queue(opts)
170
173
  @request_count += 1
174
+ if opts[:visibility_timeout]
175
+ @sqs.create_queue(queue_name, {"DefaultVisibilityTimeout" => opts[:visibility_timeout]})
176
+ else
177
+ @sqs.create_queue(queue_name)
178
+ end
171
179
  end
172
180
 
173
181
  def check_for_queue_creation_success
@@ -182,9 +190,15 @@ class SuperQueue
182
190
  def send_message_to_queue
183
191
  p = @in_buffer.shift
184
192
  payload = is_a_link?(p) ? p : encode(p)
185
- @sqs.send_message(q_url, payload)
193
+ retries = 0
194
+ begin
195
+ @request_count += 1
196
+ @sqs.send_message(q_url, payload)
197
+ rescue Excon::Errors::BadRequest => e
198
+ retries += 1
199
+ (retries >= 10) ? retry : raise(e)
200
+ end
186
201
  @mock_length += 1 if SuperQueue.mocking?
187
- @request_count += 1
188
202
  end
189
203
 
190
204
  def get_message_from_queue
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: