queue-bus 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/queue_bus/application.rb +11 -1
- data/lib/queue_bus/task_manager.rb +7 -0
- data/lib/queue_bus/tasks.rb +12 -4
- data/lib/queue_bus/version.rb +1 -1
- data/spec/application_spec.rb +50 -8
- data/spec/subscription_list_spec.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 315c7263eb40e8d6165b96b8f50738ff5861127f35f1ce282f7b1d8a20914290
|
4
|
+
data.tar.gz: 067034c67ce6232de23fe552c1fc3bac50ca64dd898dec9b4958009ce6067fe9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfea248252d2b17eca07eb5dae5e7feb4e32ac8673f154f959f0a622221dd466470f0b243f2e8c07191c951897b646c8341e5df3933556361dc1fd831de483a6
|
7
|
+
data.tar.gz: 6585cc65f3bb494161fc18e45d421203278db133b3471747caa8d526da7a551b524a6ba6289320f4a6f7fe80566f6bb7436dadda267d69d96497c7e2f14e64a2
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [0.10.0]
|
10
|
+
|
11
|
+
### Added
|
12
|
+
- Ability to unsubscribe from specific queues in an application (`Application#unsubscribe_queue`).
|
13
|
+
- `rake queuebus:unsubscribe` can now take two parameters to unsubscribe from specific queues, e.g. `rake queuebus:unsubscribe[my_app_key, my_queue_name]`.
|
14
|
+
|
9
15
|
## [0.9.1]
|
10
16
|
|
11
17
|
### Added
|
@@ -32,6 +32,7 @@ module QueueBus
|
|
32
32
|
|
33
33
|
::QueueBus.redis do |redis|
|
34
34
|
redis_hash = subscription_list.to_redis
|
35
|
+
|
35
36
|
redis_hash.each do |key, hash|
|
36
37
|
redis.hset(temp_key, key, QueueBus::Util.encode(hash))
|
37
38
|
end
|
@@ -46,8 +47,17 @@ module QueueBus
|
|
46
47
|
true
|
47
48
|
end
|
48
49
|
|
50
|
+
def unsubscribe_queue(queue)
|
51
|
+
# Filters out all subscriptions that match the supplied queue name.
|
52
|
+
::QueueBus.redis do |redis|
|
53
|
+
read_redis_hash.each do |key, hash_details|
|
54
|
+
redis.hdel(redis_key, key) if queue == hash_details["queue_name"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
def unsubscribe
|
50
|
-
#
|
60
|
+
# Remove everything.
|
51
61
|
::QueueBus.redis do |redis|
|
52
62
|
redis.srem(self.class.app_list_key, app_key)
|
53
63
|
redis.del(redis_key)
|
@@ -24,6 +24,13 @@ module QueueBus
|
|
24
24
|
count
|
25
25
|
end
|
26
26
|
|
27
|
+
def unsubscribe_queue!(app_key, queue)
|
28
|
+
log "Unsubcribing #{queue} from #{app_key}"
|
29
|
+
app = ::QueueBus::Application.new(app_key)
|
30
|
+
app.unsubscribe_queue(queue)
|
31
|
+
log " ...done"
|
32
|
+
end
|
33
|
+
|
27
34
|
def unsubscribe!
|
28
35
|
count = 0
|
29
36
|
::QueueBus.dispatchers.each do |dispatcher|
|
data/lib/queue_bus/tasks.rb
CHANGED
@@ -12,11 +12,19 @@ namespace :queuebus do
|
|
12
12
|
raise 'No subscriptions created' if count == 0
|
13
13
|
end
|
14
14
|
|
15
|
-
desc
|
16
|
-
task unsubscribe: [:preload] do
|
15
|
+
desc "Unsubscribes this application from QueueBus events"
|
16
|
+
task :unsubscribe, [:app_key, :queue] => [ :preload ] do |task, args|
|
17
|
+
app_key = args[:app_key]
|
18
|
+
queue = args[:queue]
|
17
19
|
manager = ::QueueBus::TaskManager.new(true)
|
18
|
-
|
19
|
-
|
20
|
+
|
21
|
+
if app_key && queue
|
22
|
+
manager.unsubscribe_queue!(app_key, queue)
|
23
|
+
else
|
24
|
+
manager = ::QueueBus::TaskManager.new(true)
|
25
|
+
count = manager.unsubscribe!
|
26
|
+
puts "No subscriptions unsubscribed" if count == 0
|
27
|
+
end
|
20
28
|
end
|
21
29
|
|
22
30
|
desc 'List QueueBus queues that need worked'
|
data/lib/queue_bus/version.rb
CHANGED
data/spec/application_spec.rb
CHANGED
@@ -102,16 +102,58 @@ module QueueBus
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
describe
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
105
|
+
describe "#unsubscribe" do
|
106
|
+
context "when a queue is not specified" do
|
107
|
+
it "removes all subscriptions" do
|
108
|
+
myapp_list = SubscriptionList.new
|
109
|
+
other_list = SubscriptionList.new
|
110
|
+
|
111
|
+
subscription_1 = Subscription.new("myapp_default", "key1", "MyClass1", {"bus_event_type" => "event_one"})
|
112
|
+
subscription_2 = Subscription.new("myapp_default", "key2", "MyClass2", {"bus_event_type" => "event_two"})
|
113
|
+
subscription_3 = Subscription.new("myapp_other_queue", "key1", "MyClass1", {"bus_event_type" => "event_one"})
|
114
|
+
|
115
|
+
myapp_list.add(subscription_1)
|
116
|
+
myapp_list.add(subscription_2)
|
117
|
+
other_list.add(subscription_3)
|
118
|
+
|
119
|
+
Application.new("myapp").subscribe(myapp_list)
|
120
|
+
Application.new("other").subscribe(other_list)
|
121
|
+
|
122
|
+
expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({
|
123
|
+
"key1" => "{\"queue_name\":\"myapp_default\",\"key\":\"key1\",\"class\":\"MyClass1\",\"matcher\":{\"bus_event_type\":\"event_one\"}}",
|
124
|
+
"key2" => "{\"queue_name\":\"myapp_default\",\"key\":\"key2\",\"class\":\"MyClass2\",\"matcher\":{\"bus_event_type\":\"event_two\"}}"
|
125
|
+
})
|
126
|
+
|
127
|
+
Application.new("myapp").unsubscribe
|
128
|
+
|
129
|
+
expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to eq(["other"])
|
130
|
+
expect(QueueBus.redis { |redis| redis.hlen("bus_app:myapp") }).to eq(0)
|
131
|
+
expect(QueueBus.redis { |redis| redis.hlen("bus_app:other") }).to eq(1)
|
132
|
+
end
|
133
|
+
end
|
110
134
|
|
111
|
-
|
135
|
+
context "when a queue is specified" do
|
136
|
+
it "removes only that key" do
|
137
|
+
list = SubscriptionList.new
|
112
138
|
|
113
|
-
|
114
|
-
|
139
|
+
subscription_1 = Subscription.new("myapp_default", "key1", "MyClass1", {"bus_event_type" => "event_one"})
|
140
|
+
subscription_2 = Subscription.new("myapp_other_queue", "key2", "MyClass2", {"bus_event_type" => "event_two"})
|
141
|
+
|
142
|
+
list.add(subscription_1)
|
143
|
+
list.add(subscription_2)
|
144
|
+
|
145
|
+
Application.new("myapp").subscribe(list)
|
146
|
+
|
147
|
+
expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({
|
148
|
+
"key1" => "{\"queue_name\":\"myapp_default\",\"key\":\"key1\",\"class\":\"MyClass1\",\"matcher\":{\"bus_event_type\":\"event_one\"}}",
|
149
|
+
"key2" => "{\"queue_name\":\"myapp_other_queue\",\"key\":\"key2\",\"class\":\"MyClass2\",\"matcher\":{\"bus_event_type\":\"event_two\"}}"
|
150
|
+
})
|
151
|
+
|
152
|
+
Application.new("myapp").unsubscribe_queue("myapp_default")
|
153
|
+
|
154
|
+
expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to eq(["myapp"])
|
155
|
+
expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"key2" => "{\"queue_name\":\"myapp_other_queue\",\"key\":\"key2\",\"class\":\"MyClass2\",\"matcher\":{\"bus_event_type\":\"event_two\"}}"})
|
156
|
+
end
|
115
157
|
end
|
116
158
|
end
|
117
159
|
|
@@ -48,5 +48,31 @@ module QueueBus
|
|
48
48
|
'key2' => { 'queue_name' => 'else_ok', 'key' => 'key2', 'class' => 'MyClass', 'matcher' => { 'bus_event_type' => 'event_two' } })
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
context "when modifying the subscription" do
|
53
|
+
let(:list) { SubscriptionList.new }
|
54
|
+
let(:subscription_1) { Subscription.new("default", "key1", "MyClass", {"bus_event_type" => "event_one"}) }
|
55
|
+
let(:subscription_2) { Subscription.new("else_ok", "key2", "MyClass", {"bus_event_type" => "event_two"}) }
|
56
|
+
|
57
|
+
context "when adding subscriptions" do
|
58
|
+
it "adds the subscription successfully" do
|
59
|
+
list.add(subscription_1)
|
60
|
+
list.add(subscription_2)
|
61
|
+
|
62
|
+
expect(list.to_redis).to eq(
|
63
|
+
{
|
64
|
+
"key1" => {"queue_name" => "default", "key" => "key1", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_one"}},
|
65
|
+
"key2" => {"queue_name" => "else_ok", "key" => "key2", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_two"}}
|
66
|
+
}
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "errors if the subscription already exists" do
|
71
|
+
list.add(subscription_1)
|
72
|
+
|
73
|
+
expect { list.add(subscription_1) }.to raise_exception(RuntimeError, /Duplicate key/)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
51
77
|
end
|
52
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queue-bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Leonard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|