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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f35ec72b2a6256350aabd9f2f6fa6591a1b625f404a3013ea73fb24876fb9e3
4
- data.tar.gz: 00eb73580e6160d3932f43110c182832163ab5d3f9db34d44980b831cf4f7fdc
3
+ metadata.gz: 315c7263eb40e8d6165b96b8f50738ff5861127f35f1ce282f7b1d8a20914290
4
+ data.tar.gz: 067034c67ce6232de23fe552c1fc3bac50ca64dd898dec9b4958009ce6067fe9
5
5
  SHA512:
6
- metadata.gz: 887ddce8443a1c17bc4db578a8d6b51d1a81906287db94ccd1f47681f30032cf485e1ed30e1a0feb56cc05b17162fae8f2ce28d07bad4b943a6dce7b40302c40
7
- data.tar.gz: 34394be52205690b867bc2402563a9e970fa899250009481ed460f4b4909b8b8f3782bb4c5915d33eaccf6bebf2eebcedf8961628e539af6cde08646517f792f
6
+ metadata.gz: dfea248252d2b17eca07eb5dae5e7feb4e32ac8673f154f959f0a622221dd466470f0b243f2e8c07191c951897b646c8341e5df3933556361dc1fd831de483a6
7
+ data.tar.gz: 6585cc65f3bb494161fc18e45d421203278db133b3471747caa8d526da7a551b524a6ba6289320f4a6f7fe80566f6bb7436dadda267d69d96497c7e2f14e64a2
@@ -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
- # TODO: clean up known queues?
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|
@@ -12,11 +12,19 @@ namespace :queuebus do
12
12
  raise 'No subscriptions created' if count == 0
13
13
  end
14
14
 
15
- desc 'Unsubscribes this application from QueueBus events'
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
- count = manager.unsubscribe!
19
- puts 'No subscriptions unsubscribed' if count == 0
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'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module QueueBus
4
- VERSION = '0.9.1'
4
+ VERSION = '0.10.0'
5
5
  end
@@ -102,16 +102,58 @@ module QueueBus
102
102
  end
103
103
  end
104
104
 
105
- describe '#unsubscribe' do
106
- it 'should remove items' do
107
- QueueBus.redis { |redis| redis.sadd('bus_apps', 'myapp') }
108
- QueueBus.redis { |redis| redis.sadd('bus_apps', 'other') }
109
- QueueBus.redis { |redis| redis.hset('bus_app:myapp', 'event_one', 'myapp_default') }
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
- Application.new('myapp').unsubscribe
135
+ context "when a queue is specified" do
136
+ it "removes only that key" do
137
+ list = SubscriptionList.new
112
138
 
113
- expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to eq(['other'])
114
- expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
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.9.1
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-09-16 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json