msgr 0.14.1.1.b111 → 0.14.1.1.b112
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/msgr/binding.rb +20 -10
- data/lib/msgr/client.rb +2 -2
- data/lib/msgr/connection.rb +2 -2
- data/lib/msgr/test_pool.rb +45 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTg4NDhmODcwZWU2MzEzOTQ1ODllNzg5ODdiNGFjODJiOGZmMmZiMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDUwNjY3NDU5ZWQ1ZjM1ZjdkYTE0N2YwYjg4YTRjZmFhOTYyOTEzOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2M3OGEyMWUwNTA5MGQyN2Q1MjkzMWRiNWIwYmVhZjIzNzk3ZmE5MGIwZGU4
|
10
|
+
YmQ4OTM2MGMxZjFkZmE0ZTlmNTdiNmQ4MzE5NmU1ZDgwNDdlNWEyZGU2N2U2
|
11
|
+
YjUwYjViZTg1MjIyOTdjY2M4Mjk5OThjN2I0MzNjZTVlMWRkYjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjY0OWNlMGQ0N2U3MjdmMWZmYWI1YTI2NGM0ZGQ0MjlhODA3ZDkyZWE3ZDNj
|
14
|
+
M2NjM2VmYmUzNGVmMTFjZjA1NDhjNmMzNzZiMGE5ZTJhNjBkOGFiNDZlNmI3
|
15
|
+
OGNhYmNiY2U1Nzk4ZTg0NDg4NDNmYjk0YmMxYTVlZTAxOGNjMzc=
|
data/lib/msgr/binding.rb
CHANGED
@@ -17,15 +17,7 @@ module Msgr
|
|
17
17
|
queue.bind connection.exchange, routing_key: key
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
begin
|
22
|
-
dispatcher.call Message.new(connection, *args, route)
|
23
|
-
rescue => err
|
24
|
-
log(:error) do
|
25
|
-
"Rescued error from subscribe: #{err.class.name}: #{err}\n#{err.backtrace.join("\n")}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
20
|
+
subscribe
|
29
21
|
end
|
30
22
|
|
31
23
|
def release
|
@@ -37,8 +29,26 @@ module Msgr
|
|
37
29
|
queue.delete
|
38
30
|
end
|
39
31
|
|
40
|
-
def purge
|
32
|
+
def purge(release: true)
|
33
|
+
self.release if release
|
34
|
+
|
41
35
|
queue.purge
|
36
|
+
|
37
|
+
subscribe if release
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def subscribe
|
43
|
+
@subscription = queue.subscribe(manual_ack: true) do |*args|
|
44
|
+
begin
|
45
|
+
dispatcher.call Message.new(connection, *args, route)
|
46
|
+
rescue => err
|
47
|
+
log(:error) do
|
48
|
+
"Rescued error from subscribe: #{err.class.name}: #{err}\n#{err.backtrace.join("\n")}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
data/lib/msgr/client.rb
CHANGED
@@ -71,13 +71,13 @@ module Msgr
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def purge
|
74
|
+
def purge(release: false)
|
75
75
|
mutex.synchronize do
|
76
76
|
check_process!
|
77
77
|
|
78
78
|
log(:debug) { "Purge all queues on #{uri}..." }
|
79
79
|
|
80
|
-
connection.purge
|
80
|
+
connection.purge(release: release)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
data/lib/msgr/connection.rb
CHANGED
@@ -58,11 +58,11 @@ module Msgr
|
|
58
58
|
bindings.each { |binding| binding.delete }
|
59
59
|
end
|
60
60
|
|
61
|
-
def purge
|
61
|
+
def purge(**kwargs)
|
62
62
|
return if bindings.empty?
|
63
63
|
log(:debug) { "Purge bindings (#{bindings.size})..." }
|
64
64
|
|
65
|
-
bindings.each(
|
65
|
+
bindings.each {|b| b.purge(**kwargs) }
|
66
66
|
end
|
67
67
|
|
68
68
|
def bindings
|
data/lib/msgr/test_pool.rb
CHANGED
@@ -1,30 +1,56 @@
|
|
1
1
|
module Msgr
|
2
2
|
class TestPool
|
3
3
|
def initialize(*)
|
4
|
-
@mutex = Mutex.new
|
5
4
|
@queue = []
|
5
|
+
@mutex = Mutex.new
|
6
|
+
@event = ConditionVariable.new
|
6
7
|
end
|
7
8
|
|
8
|
-
def post(
|
9
|
-
@mutex.synchronize
|
9
|
+
def post(message, &block)
|
10
|
+
@mutex.synchronize do
|
11
|
+
@queue << [block, message]
|
12
|
+
@event.signal
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
|
-
def run(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
item[0].call(*item[1])
|
16
|
+
def run(**kwargs)
|
17
|
+
@mutex.synchronize do
|
18
|
+
ns_run(**kwargs)
|
19
|
+
end
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
22
|
+
def clear
|
23
|
+
@mutex.synchronize do
|
24
|
+
@queue.clear
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
+
alias_method :reset, :clear
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def ns_run(count: 1, timeout: 5)
|
33
|
+
received = 0
|
34
|
+
|
35
|
+
while received < count
|
36
|
+
if (item = @queue.pop)
|
37
|
+
item[0].call item[1]
|
38
|
+
received += 1
|
39
|
+
else
|
40
|
+
start = Time.now.to_f
|
41
|
+
|
42
|
+
@event.wait(@mutex, timeout)
|
43
|
+
|
44
|
+
stop = Time.now.to_f
|
45
|
+
diff = stop - start
|
46
|
+
timeout -= diff
|
47
|
+
|
48
|
+
if timeout <= 0
|
49
|
+
raise TimeoutError.new \
|
50
|
+
"Expected to receive #{count} messages but received #{received}."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
28
54
|
end
|
29
55
|
|
30
56
|
class << self
|
@@ -36,9 +62,11 @@ module Msgr
|
|
36
62
|
new.run(*args)
|
37
63
|
end
|
38
64
|
|
39
|
-
def
|
40
|
-
@instance ? @instance.
|
65
|
+
def clear
|
66
|
+
@instance ? @instance.clear : nil
|
41
67
|
end
|
68
|
+
|
69
|
+
alias_method :reset, :clear
|
42
70
|
end
|
43
71
|
end
|
44
72
|
end
|