watership 0.5.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/lib/watership/consumer.rb +15 -11
- data/lib/watership/version.rb +1 -1
- data/lib/watership.rb +12 -5
- 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: d9d75218a0e116036973c5143327e02200e90d5e
|
4
|
+
data.tar.gz: 8f2ab743f84f7816d64c4bf57d9830c559c2f025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aff983c5122210505b47edcf200099e1fb4f530bdf0efaf6ae0cd624f7676e33bdb42ad772d8553855ec469735a6ba7eee9e1777e61c3f4b183eb3e67093cb5
|
7
|
+
data.tar.gz: 399868642a4ab1ba89881c720d053e940d472d9b5c7c7deeb45fe239579251e6281eee4aa97f829ae51c92ff3e9b48b3b3299097f40b3ce8a3eac3164b57f226
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.7.1 - 2014-07-22
|
4
|
+
* Fix a critical bug during reconnect
|
5
|
+
|
6
|
+
## 0.7.0 - 2014-07-21 [yanked]
|
7
|
+
* Adding bang methods to re-raise recused errors
|
8
|
+
|
9
|
+
## 0.6.0 - 2014-07-18 [yanked]
|
10
|
+
* Acknoledges failed messages after they are re-enqueued
|
11
|
+
* Added thread safety
|
12
|
+
* Added bugsnug support
|
13
|
+
|
14
|
+
## 0.5.5 - 2014-07-12
|
15
|
+
* Adding general support for Bugsnag
|
16
|
+
|
17
|
+
## 0.5.0 - 2014-07-10
|
18
|
+
* Add support for running multiple threads in a single consumer.
|
19
|
+
|
3
20
|
## 0.4.0 - 2014-07-10
|
4
21
|
* Add retry behavior on messages that generate exceptions in `Watership::Consumer`.
|
5
22
|
|
data/lib/watership/consumer.rb
CHANGED
@@ -8,19 +8,21 @@ module Watership
|
|
8
8
|
@consumer = consumer
|
9
9
|
@url = url
|
10
10
|
@prefetch = channel_options.delete(:prefetch) || Integer(ENV.fetch("RABBIT_CONSUMER_PREFETCH", 200))
|
11
|
+
@concurrency = channel_options.delete(:concurrency) || 1
|
11
12
|
@channel_opts = {durable: true}.merge(channel_options)
|
12
13
|
@queue_opts = {block: false, ack: true}.merge(queue_options)
|
13
14
|
end
|
14
15
|
|
15
|
-
def consume(
|
16
|
+
def consume(donotuse = :donotuse)
|
17
|
+
logger.error("Don't provide an argument to Consumer#consume") unless donotuse == :donotuse
|
18
|
+
|
16
19
|
Thread.abort_on_exception = true
|
17
|
-
concurrency.times do
|
20
|
+
@concurrency.times do
|
18
21
|
queue.subscribe(@queue_opts) do |delivery_info, properties, payload|
|
19
|
-
success = true
|
20
|
-
data = JSON.parse(payload)
|
21
22
|
begin
|
23
|
+
data = JSON.parse(payload)
|
22
24
|
@consumer.call(data)
|
23
|
-
|
25
|
+
success = true
|
24
26
|
rescue StandardError => exception
|
25
27
|
logger.error "Error thrown in subscribe block"
|
26
28
|
logger.error exception.message
|
@@ -28,19 +30,21 @@ module Watership
|
|
28
30
|
|
29
31
|
retries = data["retries"] || 0
|
30
32
|
|
33
|
+
Airbrake.notify(exception) if defined?(Airbrake)
|
34
|
+
Bugsnag.notify(exception, data: {payload: data, retries: retries}) if defined?(Bugsnag)
|
35
|
+
|
31
36
|
if retries.to_i < 3
|
32
37
|
Watership.enqueue(name: @consumer.class::QUEUE, payload: data.merge({retries: retries+1}))
|
38
|
+
success = true
|
33
39
|
end
|
34
|
-
|
35
|
-
Airbrake.notify(exception) if defined?(Airbrake)
|
36
|
-
Bugsnag.notify(exception, data: {payload: data, retries: retries}) if defined?(Bugsnag)
|
37
40
|
rescue Interrupt => exception
|
38
|
-
success = false
|
39
41
|
logger.error "Interrupt in subscribe block"
|
40
42
|
logger.warn "Stopped gracefully."
|
41
43
|
throw(:terminate)
|
42
44
|
ensure
|
43
|
-
|
45
|
+
if success
|
46
|
+
ack_message(delivery_info.delivery_tag)
|
47
|
+
else
|
44
48
|
reject_message(delivery_info.delivery_tag)
|
45
49
|
end
|
46
50
|
end
|
@@ -80,7 +84,7 @@ module Watership
|
|
80
84
|
|
81
85
|
def channel
|
82
86
|
@channel ||= begin
|
83
|
-
c = connection.create_channel
|
87
|
+
c = connection.create_channel(nil, @concurrency)
|
84
88
|
c.prefetch(@prefetch)
|
85
89
|
c
|
86
90
|
end
|
data/lib/watership/version.rb
CHANGED
data/lib/watership.rb
CHANGED
@@ -19,7 +19,11 @@ module Watership
|
|
19
19
|
@config = uri
|
20
20
|
end
|
21
21
|
|
22
|
-
def enqueue(options = {})
|
22
|
+
def enqueue!(options = {})
|
23
|
+
enqueue(options, true)
|
24
|
+
end
|
25
|
+
|
26
|
+
def enqueue(options = {}, reraise = false)
|
23
27
|
options = options.dup
|
24
28
|
message = options.delete(:message)
|
25
29
|
name = options.delete(:name)
|
@@ -31,6 +35,7 @@ module Watership
|
|
31
35
|
fallback.call if fallback
|
32
36
|
notify(exception)
|
33
37
|
logger.error(exception.class.name)
|
38
|
+
raise exception if reraise
|
34
39
|
end
|
35
40
|
|
36
41
|
def connect_with_queue(name, options = {})
|
@@ -38,23 +43,25 @@ module Watership
|
|
38
43
|
end
|
39
44
|
|
40
45
|
def reconnect
|
41
|
-
|
46
|
+
Thread.current[:bunny_channel] = nil
|
47
|
+
$bunny_connection = nil
|
42
48
|
channel
|
43
49
|
true
|
44
50
|
end
|
45
51
|
|
46
52
|
def channel
|
47
|
-
|
53
|
+
Thread.current[:bunny_channel] ||= connection.create_channel
|
48
54
|
rescue *CONNECTION_EXCEPTIONS => exception
|
49
55
|
notify(exception)
|
50
|
-
|
56
|
+
Thread.current[:bunny_channel] = nil
|
51
57
|
end
|
52
58
|
|
53
59
|
def connection
|
54
|
-
Bunny.new(@config).tap { |bunny| bunny.start }
|
60
|
+
$bunny_connection ||= Bunny.new(@config).tap { |bunny| bunny.start }
|
55
61
|
end
|
56
62
|
|
57
63
|
def notify(exception)
|
64
|
+
Bugsnag.notify(exception) if defined?(Bugsnag) && @env == 'production'
|
58
65
|
Airbrake.notify_or_ignore(exception) if defined?(Airbrake) && @env == 'production'
|
59
66
|
end
|
60
67
|
|
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.
|
4
|
+
version: 0.7.1
|
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-07-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|