pebbles-river 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pebbles/river/river.rb +11 -39
- data/lib/pebbles/river/version.rb +1 -1
- data/spec/lib/river_spec.rb +0 -22
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c514b0f819ee4aa389d5abaca35f3dcdc8fecd5b
|
4
|
+
data.tar.gz: dcbbe1d18db737bd37e88a919cf5597d7f671f92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7880c624a3e71b2cf73f17d13f8eb9b8be74adc5dbea419302c3ede4119892848643c72b09e217099128c7442aa0a132c1529923f9f782451bee2b01df925221
|
7
|
+
data.tar.gz: 1d5c924d2fb50c934b656b493e6db0cdc1a126ab043e9b8aced0560713562fb09d94caaec151bd4bf8ccf326e17062ead056d3b00f2cb631be7feb572d615a81
|
data/lib/pebbles/river/river.rb
CHANGED
@@ -30,15 +30,14 @@ module Pebbles
|
|
30
30
|
def connect
|
31
31
|
unless @session and @channel and @exchange
|
32
32
|
disconnect
|
33
|
-
handle_session_error do
|
34
|
-
@session = Bunny::Session.new(::Pebbles::River.rabbitmq_options)
|
35
|
-
@session.start
|
36
33
|
|
37
|
-
|
38
|
-
|
34
|
+
@session = Bunny::Session.new(::Pebbles::River.rabbitmq_options)
|
35
|
+
@session.start
|
39
36
|
|
40
|
-
|
41
|
-
|
37
|
+
@channel = @session.create_channel
|
38
|
+
@channel.prefetch(@prefetch) if @prefetch
|
39
|
+
|
40
|
+
@exchange = @channel.exchange(@exchange_name, EXCHANGE_OPTIONS.dup)
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
@@ -63,14 +62,12 @@ module Pebbles
|
|
63
62
|
end
|
64
63
|
|
65
64
|
def publish(options = {})
|
66
|
-
|
67
|
-
connect
|
65
|
+
connect
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
end
|
67
|
+
# Note: Using self.exchange so it can be stubbed in tests
|
68
|
+
self.exchange.publish(options.to_json,
|
69
|
+
persistent: options.fetch(:persistent, true),
|
70
|
+
key: Routing.routing_key_for(options.slice(:event, :uid)))
|
74
71
|
end
|
75
72
|
|
76
73
|
def queue(options = {})
|
@@ -104,31 +101,6 @@ module Pebbles
|
|
104
101
|
|
105
102
|
private
|
106
103
|
|
107
|
-
def handle_session_error(exception_klass = ConnectFailure, &block)
|
108
|
-
last_exception = nil
|
109
|
-
Timeout.timeout(MAX_RETRY_TIMEOUT) do
|
110
|
-
retry_count = 0
|
111
|
-
begin
|
112
|
-
yield
|
113
|
-
rescue Bunny::Exception => e
|
114
|
-
disconnect
|
115
|
-
last_exception = e
|
116
|
-
retry_count += 1
|
117
|
-
backoff(retry_count)
|
118
|
-
retry
|
119
|
-
end
|
120
|
-
end
|
121
|
-
rescue Timeout::Error => timeout_exception
|
122
|
-
# Timeouts can screw up the connection, so forcibly close it
|
123
|
-
disconnect
|
124
|
-
|
125
|
-
if last_exception
|
126
|
-
raise exception_klass.new(last_exception.message, last_exception)
|
127
|
-
else
|
128
|
-
raise exception_klass.new("Timeout", timeout_exception)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
104
|
def backoff(iteration)
|
133
105
|
sleep([(1.0 / 2.0 * (2.0 ** [30, iteration].min - 1.0)).ceil, MAX_BACKOFF_SECONDS].min)
|
134
106
|
end
|
data/spec/lib/river_spec.rb
CHANGED
@@ -89,28 +89,6 @@ describe Pebbles::River::River do
|
|
89
89
|
JSON.parse(payload)['uid'].should eq('klass:path$1')
|
90
90
|
end
|
91
91
|
|
92
|
-
context 'on connection timeout' do
|
93
|
-
it "gives up with SendFailure" do
|
94
|
-
exchange = double('exchange')
|
95
|
-
exchange.stub(:publish) { }
|
96
|
-
|
97
|
-
subject.stub(:exchange) { exchange }
|
98
|
-
|
99
|
-
Timeout.stub(:timeout) { |&block|
|
100
|
-
raise Timeout::Error, "execution expired"
|
101
|
-
}
|
102
|
-
expect(Timeout).to receive(:timeout).exactly(1).times
|
103
|
-
|
104
|
-
expect(-> {
|
105
|
-
subject.publish({event: 'explode', uid: 'thing:rspec$1'})
|
106
|
-
}).to raise_error do |e|
|
107
|
-
expect(e).to be_instance_of Pebbles::River::SendFailure
|
108
|
-
expect(e.message).to eq 'Timeout'
|
109
|
-
expect(e.connection_exception.class).to eq Timeout::Error
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
92
|
end
|
115
93
|
|
116
94
|
it "subscribes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebbles-river
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Staubo
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-05-
|
12
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pebblebed
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
requirements: []
|
187
187
|
rubyforge_project:
|
188
|
-
rubygems_version: 2.2
|
188
|
+
rubygems_version: 2.5.2
|
189
189
|
signing_key:
|
190
190
|
specification_version: 4
|
191
191
|
summary: Implements an event river mechanism for Pebblebed.
|
@@ -194,4 +194,3 @@ test_files:
|
|
194
194
|
- spec/lib/routing_spec.rb
|
195
195
|
- spec/lib/worker_spec.rb
|
196
196
|
- spec/spec_helper.rb
|
197
|
-
has_rdoc:
|