captainu-tincan 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tincan/sender.rb +11 -7
- data/lib/tincan/version.rb +1 -1
- data/spec/sender_spec.rb +43 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1131a74590ccc72507072e98e99b76dc664b3b9
|
4
|
+
data.tar.gz: b54e1fae869ce79d00b979bee13db4a3196c7056
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 828686330455c64a8272530833d7e571cedf158ef0bab6a77d30fe090ced1c9a34f4c3cf73092a8ef69d13a45d77187cfd868f223272ed04f7a8c04ce035261c
|
7
|
+
data.tar.gz: 7180089c5bbc803b8fe0ebadd9ee9f6d4ce4578ea80bf993864d813cc3c218c12d2c3e615eeb4c0aa912566160bbae467db70d3e316abbe1012c0366e44049f8
|
data/lib/tincan/sender.rb
CHANGED
@@ -37,11 +37,15 @@ module Tincan
|
|
37
37
|
|
38
38
|
# Asks Redis for the set of all active receivers and generates string
|
39
39
|
# keys for all of them. Formatted like "namespace:object:client:messages".
|
40
|
+
# @param [String] object_name The name of the object, used in formulating
|
41
|
+
# which receiver list keys to return.
|
42
|
+
# @param [Array] exclude An optional array of client names to exclude
|
43
|
+
# from the returned list of receiver list keys.
|
40
44
|
# @return [Array] An array of keys identifying all receiver pointer lists.
|
41
|
-
def keys_for_receivers(object_name)
|
45
|
+
def keys_for_receivers(object_name, exclude: [])
|
42
46
|
receiver_list_key = key_for_elements(object_name, 'receivers')
|
43
47
|
receivers = redis_client.smembers(receiver_list_key)
|
44
|
-
receivers.map do |receiver|
|
48
|
+
receivers.reject { |r| exclude.include?(r) }.map do |receiver|
|
45
49
|
key_for_elements(object_name, receiver, 'messages')
|
46
50
|
end
|
47
51
|
end
|
@@ -61,14 +65,14 @@ module Tincan
|
|
61
65
|
# Bundles up an object in a message object and publishes it to the Redis
|
62
66
|
# host.
|
63
67
|
# @param [Tincan::Message] message The message to publish.
|
64
|
-
# @param [
|
68
|
+
# @param [Array] exclude An optional array of client names to exclude
|
69
|
+
# from getting the published message.
|
65
70
|
# @return [Boolean] true if the operation was a success.
|
66
|
-
def publish(message)
|
71
|
+
def publish(message, exclude: [])
|
67
72
|
identifier = identifier_for_message(message)
|
68
73
|
redis_client.set(primary_key_for_message(message), message.to_json)
|
69
|
-
keys_for_receivers(message.object_name.downcase
|
70
|
-
|
71
|
-
end
|
74
|
+
keys = keys_for_receivers(message.object_name.downcase, exclude: exclude)
|
75
|
+
keys.each { |key| redis_client.rpush(key, identifier) }
|
72
76
|
true
|
73
77
|
end
|
74
78
|
|
data/lib/tincan/version.rb
CHANGED
data/spec/sender_spec.rb
CHANGED
@@ -51,6 +51,12 @@ describe Tincan::Sender do
|
|
51
51
|
result = sender.keys_for_receivers('object')
|
52
52
|
expect(result).to eq(%w(data:object:some_client:messages))
|
53
53
|
end
|
54
|
+
|
55
|
+
it 'can handle an optional list of clients to exclude' do
|
56
|
+
redis.sadd('data:object:receivers', 'bork')
|
57
|
+
result = sender.keys_for_receivers('object', exclude: 'bork')
|
58
|
+
expect(result).to eq(%w(data:object:some_client:messages))
|
59
|
+
end
|
54
60
|
end
|
55
61
|
|
56
62
|
describe :flush_all_queues_for_object do
|
@@ -84,22 +90,47 @@ describe Tincan::Sender do
|
|
84
90
|
end
|
85
91
|
|
86
92
|
before do
|
87
|
-
|
88
|
-
|
89
|
-
|
93
|
+
%w(some_client bork).each do |name|
|
94
|
+
redis.sadd('data:dummy_class:receivers', name)
|
95
|
+
end
|
90
96
|
end
|
91
97
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
+
context 'posting to all clients' do
|
99
|
+
before do
|
100
|
+
sender.publish(message)
|
101
|
+
@timestamp = Time.now.to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'publishes a message to Redis at a specific key' do
|
105
|
+
message = redis.get("data:dummy_class:messages:#{@timestamp}")
|
106
|
+
expect(message).to be_a(String)
|
107
|
+
expected = '{"object_name":"dummy_class","change_type":"create",'
|
108
|
+
expected += '"object_data":{"name":"Some Idiot"},"published_at":'
|
109
|
+
expect(message).to start_with(expected)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'also publishes a message ID to client-specific receiver lists' do
|
113
|
+
identifier = redis.lpop('data:dummy_class:some_client:messages')
|
114
|
+
expect(identifier).to eq(@timestamp.to_s)
|
115
|
+
|
116
|
+
identifier = redis.lpop('data:dummy_class:bork:messages')
|
117
|
+
expect(identifier).to eq(@timestamp.to_s)
|
118
|
+
end
|
98
119
|
end
|
99
120
|
|
100
|
-
|
101
|
-
|
102
|
-
|
121
|
+
context 'posting to non-excluded clients' do
|
122
|
+
before do
|
123
|
+
sender.publish(message, exclude: %w(bork))
|
124
|
+
@timestamp = Time.now.to_i
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'publishes message IDs to client-specific receivers, non-excluded' do
|
128
|
+
identifier = redis.lpop('data:dummy_class:some_client:messages')
|
129
|
+
expect(identifier).to eq(@timestamp.to_s)
|
130
|
+
|
131
|
+
identifier = redis.lpop('data:dummy_class:bork:messages')
|
132
|
+
expect(identifier).to be_nil
|
133
|
+
end
|
103
134
|
end
|
104
135
|
end
|
105
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: captainu-tincan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Kreeger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
196
|
version: '0'
|
197
197
|
requirements: []
|
198
198
|
rubyforge_project:
|
199
|
-
rubygems_version: 2.
|
199
|
+
rubygems_version: 2.4.1
|
200
200
|
signing_key:
|
201
201
|
specification_version: 4
|
202
202
|
summary: A simple implementation of reliable Redis messaging.
|