watership 0.3.7 → 0.4.0

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: 89e825dbc60d67c45423b86b865f630d48242239
4
- data.tar.gz: 55835caea73ac3020b4cf70c3b8bfec698825af3
3
+ metadata.gz: c343b8f27c9dfabdbef3863bda8a918eeaf0097a
4
+ data.tar.gz: 977ef5d709616c80d9c3ca07a5d05dbd0f378570
5
5
  SHA512:
6
- metadata.gz: caab85ff97258c61cef701ba7cfc19709fae52c053f134bc127015f314ebd697d4580f3e16146368778a6c3c75c6ff9a9b2149ecd4bb21a0ab8e1a526ec2d41d
7
- data.tar.gz: 87531c4b68d56233360dab2477093245ec4794849cc098def7e4304af8538dc6f99787cbd2d74575f9d784cd035218cf1a2e51b876535585822a6e83cd415399
6
+ metadata.gz: 99cc83e6ad322b28593c8ff9193343dc0f1c80a45e9a43219eeeafeb324ccde6d6057fc20edcc56c134e37716000227d60d3df045badff6d6e1fab718044c140
7
+ data.tar.gz: d763b661e3ecaa1df2bd646ae240d6eddc7a9ce865375996e7c9eef303e78afb07704460365ba448b3ac3b07050c680378fff72393e326918349ea4d4144386f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0 - 2014-07-10
4
+ * Add retry behavior on messages that generate exceptions in `Watership::Consumer`.
5
+
3
6
  ## 0.3.5, 0.3.6, 0.3.7 - 2014-06-20
4
7
  * Remove dependency on Rails in `Watership::Consumer`.
5
8
 
@@ -16,28 +16,32 @@ module Watership
16
16
  Thread.abort_on_exception = true
17
17
  begin
18
18
  queue.subscribe(@queue_opts) do |delivery_info, properties, payload|
19
- success = false
19
+ success = true
20
+ data = JSON.parse(payload)
20
21
  begin
21
- @consumer.call(JSON.parse(payload))
22
- success = true
22
+ @consumer.call(data)
23
+ ack_message(delivery_info.delivery_tag)
23
24
  rescue StandardError => exception
24
25
  logger.error "Error thrown in subscribe block"
25
26
  logger.error exception.message
26
27
  logger.error exception.backtrace.join("\n")
27
- Airbrake.notify(exception) if defined?(AirBrake)
28
- logger.info "Rejecting in rabbit"
29
- throw(:terminate)
28
+
29
+ retries = data["retries"] || 0
30
+
31
+ if retries.to_i < 3
32
+ Watership.enqueue(name: @consumer.class::QUEUE, payload: data.merge({retries: retries+1}))
33
+ end
34
+
35
+ Airbrake.notify(exception) if defined?(Airbrake)
36
+ Bugsnag.notify(exception, data: {payload: data, retries: retries}) if defined?(Bugsnag)
30
37
  rescue Interrupt => exception
38
+ success = false
31
39
  logger.error "Interrupt in subscribe block"
32
40
  logger.warn "Stopped gracefully."
33
41
  throw(:terminate)
34
42
  ensure
35
- if success
36
- logger.info "Acking message"
37
- channel.acknowledge(delivery_info.delivery_tag, false)
38
- else
39
- logger.info "Rejecting message"
40
- channel.reject(delivery_info.delivery_tag, true)
43
+ unless success
44
+ reject_message(delivery_info.delivery_tag)
41
45
  end
42
46
  end
43
47
  end
@@ -48,6 +52,15 @@ module Watership
48
52
  end
49
53
 
50
54
  private
55
+ def ack_message(tag)
56
+ logger.info "Acking message"
57
+ channel.acknowledge(tag, false)
58
+ end
59
+
60
+ def reject_message(tag)
61
+ logger.info "Rejecting message"
62
+ channel.reject(tag, true)
63
+ end
51
64
 
52
65
  def queue
53
66
  @queue ||= channel.queue(@consumer.class::QUEUE, @channel_opts)
@@ -1,3 +1,3 @@
1
1
  module Watership
2
- VERSION = '0.3.7'
2
+ VERSION = '0.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watership
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Scofield
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-20 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler