vx-consumer 0.1.3 → 0.1.4

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: a4ba824b3b9047df1c4d5fe74e531bdc1f884535
4
- data.tar.gz: f31036250c862fb2975c7ff2bb52cf8674812351
3
+ metadata.gz: 855e8429df6a59a3a5ef9343411369be93f3af1a
4
+ data.tar.gz: 0c7df3bf9e3cc3efca543a5f09ecd0051c209f0c
5
5
  SHA512:
6
- metadata.gz: b6b60d2dd3c3bdc6aeeced8807b354aff3d0815e35d87b1d2f0cd76d895981dc0c532f80343dc854f26ecfcff825980bcecce03b2acc1db1ff9545daa4a1049b
7
- data.tar.gz: bde55043df8b5d64668643cfedaeeb8caacb48bbbabf5d2f9ace3c47bc5f2b1d7aef062f03b9314b4ab079f18e79871a25ee894962c4137f871e3d038abbce26
6
+ metadata.gz: 4fcb5d02ba1364f8717e07bc34da09417e73ddffa5b1b4cc851c97822250215a81e66eb8bc8017e42376e58068ea27940528ae38aed426074d021ada219154bd
7
+ data.tar.gz: b1d57a0b754c90455467b0550086def194a1b790a079a428f4add5bb7be569e30c11da33c7ddc5b4f3c9ef09f24708a15c097ae228ea6be29c52fe82b002dcbe
@@ -24,7 +24,7 @@ module Vx
24
24
  }
25
25
 
26
26
  with_middlewares :pub, instrumentation do
27
- with_channel do |ch|
27
+ session.with_pub_channel do |ch|
28
28
  instrument("process_publishing", instrumentation.merge(channel: ch.id)) do
29
29
  encoded = encode_payload(payload, options[:content_type])
30
30
  x = session.declare_exchange ch, name, params.exchange_options
@@ -36,10 +36,6 @@ module Vx
36
36
 
37
37
  private
38
38
 
39
- def with_channel
40
- yield session.pub_channel
41
- end
42
-
43
39
  def encode_payload(payload, content_type)
44
40
  Serializer.pack(content_type, payload)
45
41
  end
@@ -98,23 +98,36 @@ module Vx
98
98
  end
99
99
  end
100
100
 
101
- def pub_channel
101
+ def with_pub_channel
102
+ key = :vx_consumer_session_pub_channel
103
+ if ch = Thread.current[key]
104
+ yield ch
105
+ else
106
+ conn.with_channel do |c|
107
+ yield c
108
+ end
109
+ end
110
+ end
111
+
112
+ def allocate_pub_channel
102
113
  assert_connection_is_open
103
114
 
104
115
  key = :vx_consumer_session_pub_channel
105
- ch = Thread.current[key]
106
116
 
107
- if ch and ch.closed?
108
- ch = nil
109
- end
110
-
111
- unless ch
117
+ if Thread.current[key]
118
+ yield
119
+ else
112
120
  ch = conn.create_channel
113
121
  assign_error_handlers_to_channel(ch)
114
- ch
122
+ Thread.current[key] = ch
123
+ begin
124
+ yield
125
+ ensure
126
+ ch = Thread.current[key]
127
+ ch.close if ch.open?
128
+ Thread.current[key] = nil
129
+ end
115
130
  end
116
-
117
- ch
118
131
  end
119
132
 
120
133
  def declare_exchange(ch, name, options = nil)
@@ -33,7 +33,9 @@ module Vx
33
33
  with_middlewares :sub, instrumentation do
34
34
  instrument("start_processing", instrumentation)
35
35
  instrument("process", instrumentation) do
36
- run_instance delivery_info, properties, payload, channel
36
+ allocate_pub_channel do
37
+ run_instance delivery_info, properties, payload, channel
38
+ end
37
39
  end
38
40
  end
39
41
  end
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module Consumer
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
data/lib/vx/consumer.rb CHANGED
@@ -77,6 +77,10 @@ module Vx
77
77
  Consumer.session
78
78
  end
79
79
 
80
+ def allocate_pub_channel
81
+ Consumer.session.allocate_pub_channel { yield }
82
+ end
83
+
80
84
  def configuration
81
85
  Consumer.configuration
82
86
  end
@@ -119,7 +119,7 @@ describe Vx::Consumer do
119
119
  end
120
120
 
121
121
  sleep 0.1
122
- Timeout.timeout(5) do
122
+ Timeout.timeout(10) do
123
123
  consumer.graceful_shutdown
124
124
  end
125
125
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny