mercury_amqp 0.1.7 → 0.1.9

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: 8abccdb5190f1e4c7ef3f6da267d4552f79a8046
4
- data.tar.gz: 554cd4fb2c1f58b3f42e5087ae40a08f9abfcc47
3
+ metadata.gz: b38b3dede66b9e8be986f8b8f3fc480e62d326b6
4
+ data.tar.gz: 4b9b9dc78020adb4eefa32e0ec25b1e846088c41
5
5
  SHA512:
6
- metadata.gz: 29e7319862aa1d7d2276ff2b5d9611771152bd84f65ed923ffaac7f68bac759f103441145eb43ffcd50a41e4288a754022bf18c18bf70581432340621bae7f0b
7
- data.tar.gz: c932237d88e0215185381df655a1711c9fd9af0f7e513a6a0f869ee37ddf2058674ea2aa73923c89d1feb2ec81b2320d4d0f7cd461e6475d42d7772c894ce585
6
+ metadata.gz: de30e69c5f7d06a9579a28d38f5604038b0227ea0b380541c582107400139862bce47ab59c9be1cc6edd19a2d88533a29a3cb0ff8b26c607f67fe2337fbdc656
7
+ data.tar.gz: 79ecf41880b13bee8f514aeb9d3aaff18d4b17ad009fdbe336c20a0384ba002db06c99398b9861258f5aef34fe79fa8658d333310f6820f844e8cea6fe01a11a
@@ -25,12 +25,16 @@ class Mercury
25
25
  username: 'guest',
26
26
  password: 'guest',
27
27
  parallelism: 1,
28
+ on_error: nil,
28
29
  &k)
29
- AMQP.connect(host: host, port: port, vhost: vhost, username: username, password: password) do |amqp|
30
+ @on_error = on_error
31
+ AMQP.connect(host: host, port: port, vhost: vhost, username: username, password: password,
32
+ on_tcp_connection_failure: server_down_error_handler) do |amqp|
30
33
  @amqp = amqp
31
34
  @channel = AMQP::Channel.new(amqp, prefetch: parallelism) do
32
35
  @channel.confirm_select
33
- install_default_error_handler
36
+ install_channel_error_handler
37
+ install_lost_connection_error_handler
34
38
  k.call(self)
35
39
  end
36
40
  end
@@ -122,7 +126,7 @@ class Mercury
122
126
  k.call(false)
123
127
  else
124
128
  # failed for unknown reason
125
- default_error_handler(ch, info)
129
+ handle_channel_error(ch, info)
126
130
  end
127
131
  end
128
132
  check.call(ch) do |result|
@@ -133,13 +137,32 @@ class Mercury
133
137
  end
134
138
  end
135
139
 
136
- def install_default_error_handler
137
- @channel.on_error(&method(:default_error_handler))
140
+ def server_down_error_handler
141
+ make_error_handler('Failed to establish connection to AMQP server. Exiting.')
138
142
  end
139
143
 
140
- def default_error_handler(_ch, info)
144
+ def install_lost_connection_error_handler
145
+ @amqp.on_tcp_connection_loss(&make_error_handler('Lost connection to AMQP server. Exiting.'))
146
+ end
147
+
148
+ def install_channel_error_handler
149
+ @channel.on_error(&method(:handle_channel_error))
150
+ end
151
+
152
+ def handle_channel_error(_ch, info)
141
153
  @amqp.close do
142
- raise "An error occurred: #{info.reply_code} - #{info.reply_text}"
154
+ make_error_handler("An error occurred: #{info.reply_code} - #{info.reply_text}").call
155
+ end
156
+ end
157
+
158
+ def make_error_handler(msg)
159
+ proc do
160
+ Logatron.error(msg)
161
+ if @on_error.respond_to?(:call)
162
+ @on_error.call(msg)
163
+ else
164
+ raise msg
165
+ end
143
166
  end
144
167
  end
145
168
 
@@ -1,3 +1,3 @@
1
1
  class Mercury
2
- VERSION = '0.1.7'
2
+ VERSION = '0.1.9'
3
3
  end
@@ -268,6 +268,7 @@ describe Mercury::Monadic do
268
268
  let(:m2) { Mercury::Monadic.open }
269
269
  and_then { m2.start_worker(worker, source, &msgs.method(:push)) }
270
270
  and_then { wait_until { msgs.size == 2 } }
271
+ and_then { m2.close }
271
272
  end
272
273
  end
273
274
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercury_amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Winton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler