sidekiq-bus 0.5.10 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.mdown +23 -1
- data/lib/sidekiq-bus.rb +43 -3
- data/lib/sidekiq_bus/version.rb +1 -1
- data/spec/adapter/integration_spec.rb +20 -20
- data/spec/adapter_spec.rb +2 -2
- data/spec/application_spec.rb +48 -48
- data/spec/config_spec.rb +18 -18
- data/spec/dispatch_spec.rb +12 -12
- data/spec/driver_spec.rb +30 -30
- data/spec/heartbeat_spec.rb +3 -3
- data/spec/integration_spec.rb +23 -23
- data/spec/matcher_spec.rb +70 -70
- data/spec/publish_spec.rb +20 -20
- data/spec/rider_spec.rb +7 -7
- data/spec/sidekiq_bus_spec.rb +122 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/subscriber_spec.rb +98 -98
- data/spec/subscription_list_spec.rb +13 -13
- data/spec/subscription_spec.rb +17 -17
- data/spec/worker_spec.rb +6 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63c03ac9abef7e30948f4e1cc83d499251853846
|
4
|
+
data.tar.gz: ac25e298ce8dab9160026a2bdd8c5eaba099198b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fa90c9f87a6e27c8a9a29c0d5823460874fb37c99812addaca062788aed32b9cb769f9997006d9c671f4adfbc9e4400e8b0a9d80810b22c79d797eca4f58c85
|
7
|
+
data.tar.gz: 39cd967a17827ec6c8c7f0b0a8a767db802b33e32fe6bbfe2508e67f52a1a1e3471e97c17ceb0d0d46b25e398f2d56c2c54a1dadb4e7cf83ce17e4c1792f42cb
|
data/README.mdown
CHANGED
@@ -11,7 +11,6 @@ To install, include the 'sidekiq-bus' gem and add the following to your Rakefile
|
|
11
11
|
require "sidekiq_bus/tasks"
|
12
12
|
```
|
13
13
|
|
14
|
-
|
15
14
|
### Example
|
16
15
|
|
17
16
|
Application A can publish an event
|
@@ -108,6 +107,29 @@ end
|
|
108
107
|
|
109
108
|
Note: This subscribes when this class is loaded, so it needs to be in your load or otherwise referenced/required during app initialization to work properly.
|
110
109
|
|
110
|
+
### sidekiq.rb
|
111
|
+
|
112
|
+
To make sure that your sidekiq server is consuming on the proper queues, add code like
|
113
|
+
this to your `config/sidekiq.rb` file:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# config/sidekiq.rb
|
117
|
+
|
118
|
+
# Load the environment here
|
119
|
+
require './boot.rb'
|
120
|
+
|
121
|
+
if Sidekiq.server?
|
122
|
+
# Load the queues into sidekiq:
|
123
|
+
weights = {
|
124
|
+
'app_events' => 10,
|
125
|
+
'app_heartbeat' => 3,
|
126
|
+
'app_refresh' => 1
|
127
|
+
}
|
128
|
+
Sidekiq.options[:queues] =
|
129
|
+
SidekiqBus.generate_weighted_queues(overrides: weights, default: 2)
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
111
133
|
### Commands
|
112
134
|
|
113
135
|
Each app needs to tell Redis about its subscriptions:
|
data/lib/sidekiq-bus.rb
CHANGED
@@ -1,6 +1,46 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'queue-bus'
|
4
|
+
require 'sidekiq_bus/adapter'
|
5
|
+
require 'sidekiq_bus/version'
|
4
6
|
require 'sidekiq_bus/middleware/retry'
|
5
7
|
|
6
8
|
QueueBus.adapter = QueueBus::Adapters::Sidekiq.new
|
9
|
+
|
10
|
+
module SidekiqBus
|
11
|
+
# This method will analyze the current queues and generate an array that
|
12
|
+
# can operate as the sidekiq queues configuration. It should be based on how
|
13
|
+
# The sidekiq CLI builds weighted queues.
|
14
|
+
#
|
15
|
+
# @param overrides [Hash<String, Integer>] A mapping of queue names and
|
16
|
+
# weights that must be included
|
17
|
+
# @param default [Integer] The default weight to apply to any given queue
|
18
|
+
# @returns [Array<String>] The set of queue names weighted to sidekiq
|
19
|
+
def self.generate_weighted_queues(overrides: {}, default: 1)
|
20
|
+
# Gathers all queues and overrides as strictly strings
|
21
|
+
queues = Set.new(QueueBus::TaskManager.new(false).queue_names.map(&:to_s))
|
22
|
+
overrides = overrides.each_with_object({}) { |(q, w), h| h[q.to_s] = w }
|
23
|
+
overrides.default = default
|
24
|
+
|
25
|
+
# Also pitches-in for driving the bus.
|
26
|
+
queues << 'bus_incoming'
|
27
|
+
|
28
|
+
# Make sure every queue from the overrides is included
|
29
|
+
queues += overrides.keys
|
30
|
+
|
31
|
+
entry = Struct.new(:queue, :weight)
|
32
|
+
|
33
|
+
# Map all queue names to their weights and returns them as entries
|
34
|
+
entries = queues.map { |q| entry.new(q, [1, overrides[q]].max) }
|
35
|
+
|
36
|
+
# Sorts by weight to provide a visual indication of queue order in sidekiq
|
37
|
+
# UI. Otherwise they can appear in various orders. They will be sorted
|
38
|
+
# from greatest to least weight. The negative sign on the weight is key to
|
39
|
+
# making this work.
|
40
|
+
entries = entries.sort_by { |e| [-e.weight, e.queue] }
|
41
|
+
|
42
|
+
# Creates an array of N length with the same queue name (N=weight) then
|
43
|
+
# flattened into a single array
|
44
|
+
entries.flat_map { |e| Array.new(e.weight, e.queue) }
|
45
|
+
end
|
46
|
+
end
|
data/lib/sidekiq_bus/version.rb
CHANGED
@@ -19,26 +19,26 @@ describe "Sidekiq Integration" do
|
|
19
19
|
|
20
20
|
it "should publish and receive" do
|
21
21
|
Sidekiq::Testing.fake!
|
22
|
-
QueueBus::Runner1.value.
|
22
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
23
23
|
|
24
24
|
QueueBus.publish("event_name", "ok" => true)
|
25
|
-
QueueBus::Runner1.value.
|
25
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
26
26
|
|
27
27
|
QueueBus::Worker.perform_one
|
28
28
|
|
29
|
-
QueueBus::Runner1.value.
|
29
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
30
30
|
|
31
31
|
QueueBus::Worker.perform_one
|
32
32
|
|
33
|
-
QueueBus::Runner1.value.
|
33
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should publish and receive" do
|
37
37
|
Sidekiq::Testing.inline!
|
38
|
-
QueueBus::Runner1.value.
|
38
|
+
expect(QueueBus::Runner1.value).to eq(0)
|
39
39
|
|
40
40
|
QueueBus.publish("event_name", "ok" => true)
|
41
|
-
QueueBus::Runner1.value.
|
41
|
+
expect(QueueBus::Runner1.value).to eq(1)
|
42
42
|
end
|
43
43
|
|
44
44
|
end
|
@@ -46,7 +46,7 @@ describe "Sidekiq Integration" do
|
|
46
46
|
describe "Delayed Publishing" do
|
47
47
|
before(:each) do
|
48
48
|
Timecop.freeze(now)
|
49
|
-
QueueBus.
|
49
|
+
allow(QueueBus).to receive(:generate_uuid).and_return("idfhlkj")
|
50
50
|
end
|
51
51
|
after(:each) do
|
52
52
|
Timecop.return
|
@@ -69,10 +69,10 @@ describe "Sidekiq Integration" do
|
|
69
69
|
|
70
70
|
hash = JSON.parse(val)
|
71
71
|
|
72
|
-
hash["class"].
|
73
|
-
hash["args"].size.
|
74
|
-
JSON.parse(hash["args"].first).
|
75
|
-
hash["queue"].
|
72
|
+
expect(hash["class"]).to eq("QueueBus::Worker")
|
73
|
+
expect(hash["args"].size).to eq(1)
|
74
|
+
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs))
|
75
|
+
expect(hash["queue"]).to eq("bus_incoming")
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should move it to the real queue when processing" do
|
@@ -80,12 +80,12 @@ describe "Sidekiq Integration" do
|
|
80
80
|
event_name = "event_name"
|
81
81
|
|
82
82
|
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
83
|
-
val.
|
83
|
+
expect(val).to eq(nil)
|
84
84
|
|
85
85
|
QueueBus.publish_at(future, event_name, hash)
|
86
86
|
|
87
87
|
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
88
|
-
val.
|
88
|
+
expect(val).to eq(nil) # nothing really added
|
89
89
|
|
90
90
|
if Sidekiq::VERSION < '4'
|
91
91
|
Sidekiq::Scheduled::Poller.new.poll
|
@@ -94,7 +94,7 @@ describe "Sidekiq Integration" do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
97
|
-
val.
|
97
|
+
expect(val).to eq(nil) # nothing added yet
|
98
98
|
|
99
99
|
# process scheduler in future
|
100
100
|
Timecop.freeze(worktime) do
|
@@ -106,17 +106,17 @@ describe "Sidekiq Integration" do
|
|
106
106
|
|
107
107
|
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
108
108
|
hash = JSON.parse(val)
|
109
|
-
hash["class"].
|
110
|
-
hash["args"].size.
|
111
|
-
JSON.parse(hash["args"].first).
|
109
|
+
expect(hash["class"]).to eq("QueueBus::Worker")
|
110
|
+
expect(hash["args"].size).to eq(1)
|
111
|
+
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs))
|
112
112
|
|
113
113
|
QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
|
114
114
|
|
115
115
|
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
116
116
|
hash = JSON.parse(val)
|
117
|
-
hash["class"].
|
118
|
-
hash["args"].size.
|
119
|
-
JSON.parse(hash["args"].first).
|
117
|
+
expect(hash["class"]).to eq("QueueBus::Worker")
|
118
|
+
expect(hash["args"].size).to eq(1)
|
119
|
+
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy" => "QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs))
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
data/spec/adapter_spec.rb
CHANGED
@@ -3,12 +3,12 @@ require 'spec_helper'
|
|
3
3
|
describe "adapter is set" do
|
4
4
|
it "should call it's enabled! method on init" do
|
5
5
|
QueueBus.send(:reset)
|
6
|
-
adapter_under_test_class.
|
6
|
+
expect_any_instance_of(adapter_under_test_class).to receive(:enabled!)
|
7
7
|
instance = adapter_under_test_class.new
|
8
8
|
QueueBus.send(:reset)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should be defaulting to Data from spec_helper" do
|
12
|
-
QueueBus.adapter.is_a?(adapter_under_test_class).
|
12
|
+
expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
|
13
13
|
end
|
14
14
|
end
|
data/spec/application_spec.rb
CHANGED
@@ -4,42 +4,42 @@ module QueueBus
|
|
4
4
|
describe Application do
|
5
5
|
describe ".all" do
|
6
6
|
it "should return empty array when none" do
|
7
|
-
Application.all.
|
7
|
+
expect(Application.all).to eq([])
|
8
8
|
end
|
9
9
|
it "should return registered applications when there are some" do
|
10
10
|
Application.new("One").subscribe(test_list(test_sub("fdksjh")))
|
11
11
|
Application.new("Two").subscribe(test_list(test_sub("fdklhf")))
|
12
12
|
Application.new("Three").subscribe(test_list(test_sub("fkld")))
|
13
13
|
|
14
|
-
Application.all.collect(&:app_key).
|
14
|
+
expect(Application.all.collect(&:app_key)).to match_array(["one", "two", "three"])
|
15
15
|
|
16
16
|
Application.new("two").unsubscribe
|
17
|
-
Application.all.collect(&:app_key).
|
17
|
+
expect(Application.all.collect(&:app_key)).to match_array(["one", "three"])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe ".new" do
|
22
22
|
it "should have a key" do
|
23
|
-
Application.new("something").app_key.
|
23
|
+
expect(Application.new("something").app_key).to eq("something")
|
24
24
|
|
25
|
-
Application.new("some thing").app_key.
|
26
|
-
Application.new("some-thing").app_key.
|
27
|
-
Application.new("some_thing").app_key.
|
28
|
-
Application.new("Some Thing").app_key.
|
25
|
+
expect(Application.new("some thing").app_key).to eq("some_thing")
|
26
|
+
expect(Application.new("some-thing").app_key).to eq("some_thing")
|
27
|
+
expect(Application.new("some_thing").app_key).to eq("some_thing")
|
28
|
+
expect(Application.new("Some Thing").app_key).to eq("some_thing")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should raise an error if not valid" do
|
32
|
-
|
32
|
+
expect {
|
33
33
|
Application.new("")
|
34
|
-
}.
|
34
|
+
}.to raise_error("Invalid application name")
|
35
35
|
|
36
|
-
|
36
|
+
expect {
|
37
37
|
Application.new(nil)
|
38
|
-
}.
|
38
|
+
}.to raise_error("Invalid application name")
|
39
39
|
|
40
|
-
|
40
|
+
expect {
|
41
41
|
Application.new("/")
|
42
|
-
}.
|
42
|
+
}.to raise_error("Invalid application name")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -50,7 +50,7 @@ module QueueBus
|
|
50
50
|
QueueBus.redis { |redis| redis.hset("bus_app:myapp", "old_one", "oldqueue_name") }
|
51
51
|
app = Application.new("myapp")
|
52
52
|
val = app.send(:read_redis_hash)
|
53
|
-
val.
|
53
|
+
expect(val).to eq({"new_one" => {"queue_name" => "x", "bus_event_type" => "event_name"}, "old_one" => "oldqueue_name"})
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -59,45 +59,45 @@ module QueueBus
|
|
59
59
|
let(:sub2) { test_sub("event_two", "default") }
|
60
60
|
let(:sub3) { test_sub("event_three", "other") }
|
61
61
|
it "should add array to redis" do
|
62
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
62
|
+
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
63
63
|
Application.new("myapp").subscribe(test_list(sub1, sub2))
|
64
64
|
|
65
|
-
QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }.
|
66
|
-
"event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"}
|
67
|
-
QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }.
|
68
|
-
QueueBus.redis { |redis| redis.smembers("bus_apps") }.
|
65
|
+
expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"event_two"=>"{\"queue_name\":\"default\",\"key\":\"event_two\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_two\"}}",
|
66
|
+
"event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"})
|
67
|
+
expect(QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }).to match_array(["event_one", "event_two"])
|
68
|
+
expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to match_array(["myapp"])
|
69
69
|
end
|
70
70
|
it "should add string to redis" do
|
71
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
71
|
+
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
72
72
|
Application.new("myapp").subscribe(test_list(sub1))
|
73
73
|
|
74
|
-
QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }.
|
75
|
-
QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }.
|
76
|
-
QueueBus.redis { |redis| redis.smembers("bus_apps") }.
|
74
|
+
expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}"})
|
75
|
+
expect(QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }).to match_array(["event_one"])
|
76
|
+
expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to match_array(["myapp"])
|
77
77
|
end
|
78
78
|
it "should multiple queues to redis" do
|
79
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
79
|
+
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
80
80
|
Application.new("myapp").subscribe(test_list(sub1, sub2, sub3))
|
81
|
-
QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }.
|
82
|
-
"event_three"=>"{\"queue_name\":\"other\",\"key\":\"event_three\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_three\"}}"}
|
83
|
-
QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }.
|
84
|
-
QueueBus.redis { |redis| redis.smembers("bus_apps") }.
|
81
|
+
expect(QueueBus.redis { |redis| redis.hgetall("bus_app:myapp") }).to eq({"event_two"=>"{\"queue_name\":\"default\",\"key\":\"event_two\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_two\"}}", "event_one"=>"{\"queue_name\":\"default\",\"key\":\"event_one\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_one\"}}",
|
82
|
+
"event_three"=>"{\"queue_name\":\"other\",\"key\":\"event_three\",\"class\":\"::QueueBus::Rider\",\"matcher\":{\"bus_event_type\":\"event_three\"}}"})
|
83
|
+
expect(QueueBus.redis { |redis| redis.hkeys("bus_app:myapp") }).to match_array(["event_three", "event_two", "event_one"])
|
84
|
+
expect(QueueBus.redis { |redis| redis.smembers("bus_apps") }).to match_array(["myapp"])
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should do nothing if nil or empty" do
|
88
88
|
|
89
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
89
|
+
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
90
90
|
|
91
91
|
Application.new("myapp").subscribe(nil)
|
92
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
92
|
+
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
93
93
|
|
94
94
|
Application.new("myapp").subscribe([])
|
95
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
95
|
+
expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should call unsubscribe" do
|
99
99
|
app = Application.new("myapp")
|
100
|
-
app.
|
100
|
+
expect(app).to receive(:unsubscribe)
|
101
101
|
app.subscribe([])
|
102
102
|
end
|
103
103
|
end
|
@@ -110,42 +110,42 @@ module QueueBus
|
|
110
110
|
|
111
111
|
Application.new("myapp").unsubscribe
|
112
112
|
|
113
|
-
QueueBus.redis { |redis| redis.smembers("bus_apps") }.
|
114
|
-
QueueBus.redis { |redis| redis.get("bus_app:myapp") }.
|
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
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
describe "#subscription_matches" do
|
119
119
|
it "should return if it is there" do
|
120
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
120
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
|
121
121
|
|
122
122
|
subs = test_list(test_sub("one_x"), test_sub("one_y"), test_sub("one"), test_sub("two"))
|
123
123
|
Application.new("myapp").subscribe(subs)
|
124
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
124
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
|
125
125
|
|
126
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"two").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
127
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
126
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"two").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "two", "default", "::QueueBus::Rider"]])
|
127
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one", "default", "::QueueBus::Rider"]])
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should handle * wildcards" do
|
131
131
|
subs = test_list(test_sub("one.+"), test_sub("one"), test_sub("one_.*"), test_sub("two"))
|
132
132
|
Application.new("myapp").subscribe(subs)
|
133
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
133
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
|
134
134
|
|
135
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
136
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
137
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
135
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one.+", "default", "::QueueBus::Rider"]])
|
136
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one", "default", "::QueueBus::Rider"]])
|
137
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one.+","default", "::QueueBus::Rider"], ["myapp", "one_.*", "default", "::QueueBus::Rider"]])
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should handle actual regular expressions" do
|
141
141
|
subs = test_list(test_sub(/one.+/), test_sub("one"), test_sub(/one_.*/), test_sub("two"))
|
142
142
|
Application.new("myapp").subscribe(subs)
|
143
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
143
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"three").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to eq([])
|
144
144
|
|
145
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
146
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"donex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
147
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
148
|
-
Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}.
|
145
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"onex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"]])
|
146
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"donex").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"]])
|
147
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "one" ,"default", "::QueueBus::Rider"]])
|
148
|
+
expect(Application.new("myapp").subscription_matches("bus_event_type"=>"one_x").collect{|s| [s.app_key, s.key, s.queue_name, s.class_name]}).to match_array([["myapp", "(?-mix:one.+)", "default", "::QueueBus::Rider"], ["myapp", "(?-mix:one_.*)", "default", "::QueueBus::Rider"]])
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -10,51 +10,51 @@ end
|
|
10
10
|
|
11
11
|
describe "QueueBus config" do
|
12
12
|
it "should set the default app key" do
|
13
|
-
QueueBus.default_app_key.
|
13
|
+
expect(QueueBus.default_app_key).to eq(nil)
|
14
14
|
|
15
15
|
QueueBus.default_app_key = "my_app"
|
16
|
-
QueueBus.default_app_key.
|
16
|
+
expect(QueueBus.default_app_key).to eq("my_app")
|
17
17
|
|
18
18
|
QueueBus.default_app_key = "something here"
|
19
|
-
QueueBus.default_app_key.
|
19
|
+
expect(QueueBus.default_app_key).to eq("something_here")
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should set the default queue" do
|
23
|
-
QueueBus.default_queue.
|
23
|
+
expect(QueueBus.default_queue).to eq(nil)
|
24
24
|
|
25
25
|
QueueBus.default_queue = "my_queue"
|
26
|
-
QueueBus.default_queue.
|
26
|
+
expect(QueueBus.default_queue).to eq("my_queue")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should set the local mode" do
|
30
|
-
QueueBus.local_mode.
|
30
|
+
expect(QueueBus.local_mode).to eq(nil)
|
31
31
|
QueueBus.local_mode = :standalone
|
32
|
-
QueueBus.local_mode.
|
32
|
+
expect(QueueBus.local_mode).to eq(:standalone)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should set the hostname" do
|
36
|
-
QueueBus.hostname.
|
36
|
+
expect(QueueBus.hostname).not_to eq(nil)
|
37
37
|
QueueBus.hostname = "whatever"
|
38
|
-
QueueBus.hostname.
|
38
|
+
expect(QueueBus.hostname).to eq("whatever")
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should set before_publish callback" do
|
42
42
|
QueueBus.before_publish = lambda {|attributes| 42 }
|
43
|
-
QueueBus.before_publish_callback({}).
|
43
|
+
expect(QueueBus.before_publish_callback({})).to eq(42)
|
44
44
|
end
|
45
45
|
|
46
46
|
|
47
47
|
it "should use the default Redis connection" do
|
48
|
-
QueueBus.redis { |redis| redis }.
|
48
|
+
expect(QueueBus.redis { |redis| redis }).not_to eq(nil)
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should default to given adapter" do
|
52
|
-
QueueBus.adapter.is_a?(adapter_under_test_class).
|
52
|
+
expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
|
53
53
|
|
54
54
|
# and should raise if already set
|
55
|
-
|
55
|
+
expect {
|
56
56
|
QueueBus.adapter = :data
|
57
|
-
}.
|
57
|
+
}.to raise_error("Adapter already set to QueueBus::Adapters::Sidekiq")
|
58
58
|
end
|
59
59
|
|
60
60
|
context "with a fresh load" do
|
@@ -64,18 +64,18 @@ describe "QueueBus config" do
|
|
64
64
|
|
65
65
|
it "should be able to be set to resque" do
|
66
66
|
QueueBus.adapter = adapter_under_test_symbol
|
67
|
-
QueueBus.adapter.is_a?(adapter_under_test_class).
|
67
|
+
expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
|
68
68
|
|
69
69
|
# and should raise if already set
|
70
|
-
|
70
|
+
expect {
|
71
71
|
QueueBus.adapter = :data
|
72
|
-
}.
|
72
|
+
}.to raise_error("Adapter already set to QueueBus::Adapters::Sidekiq")
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should be able to be set to something else" do
|
76
76
|
|
77
77
|
QueueBus.adapter = :test_one
|
78
|
-
QueueBus.adapter.is_a?(QueueBus::Adapters::TestOne).
|
78
|
+
expect(QueueBus.adapter.is_a?(QueueBus::Adapters::TestOne)).to eq(true)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|