lolitra 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -214,17 +214,7 @@ module Lolitra
214
214
  def subscribe_to_messages(queue_name, options, handler_class)
215
215
  create_channel(self.connection) do |channel|
216
216
  channel.prefetch(1).queue(queue_name, options.merge(@options[:queue_params])).subscribe(:ack => true) do |info, payload|
217
- begin
218
- Lolitra::logger.debug("Message recived: #{info.routing_key}")
219
- Lolitra::logger.debug("#{payload}")
220
- message_class_tmp = handler_class.handlers[info.routing_key][0]
221
- handler_class.handle(message_class_tmp.unmarshall(payload))
222
- info.ack
223
- rescue => e
224
- channel.reject(info.delivery_tag, false)
225
- Lolitra::log_exception(e)
226
- mark_deadletter
227
- end
217
+ process_message(handler_class, channel, info, payload)
228
218
  end
229
219
  end
230
220
  end
@@ -236,5 +226,25 @@ module Lolitra
236
226
  def mark_deadletter
237
227
  FileUtils.touch("#{Dir.pwd}/tmp/deadletter")
238
228
  end
229
+
230
+ def process_message(handler_class, channel, info, payload, remaining_attempts=5)
231
+ begin
232
+ Lolitra::logger.debug("Message recived: #{info.routing_key}")
233
+ Lolitra::logger.debug("#{payload}")
234
+ message_class_tmp = handler_class.handlers[info.routing_key][0]
235
+ handler_class.handle(message_class_tmp.unmarshall(payload))
236
+ info.ack
237
+ rescue => e
238
+ if remaining_attempts > 0
239
+ EventMachine.add_timer(0.5) do
240
+ process_message(handler_class, channel, info, payload, remaining_attempts - 1)
241
+ end
242
+ else
243
+ mark_deadletter
244
+ channel.reject(info.delivery_tag, false)
245
+ Lolitra::log_exception(e)
246
+ end
247
+ end
248
+ end
239
249
  end
240
250
  end
@@ -1,3 +1,3 @@
1
1
  module Lolitra
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Hugo Freire
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2015-03-20 00:00:00 +01:00
17
+ date: 2015-03-26 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency