queue-bus 0.5.9 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +16 -0
- data/lib/queue-bus.rb +2 -1
- data/lib/queue_bus/config.rb +4 -0
- data/lib/queue_bus/middleware.rb +54 -0
- data/lib/queue_bus/version.rb +1 -1
- data/lib/queue_bus/worker.rb +3 -1
- data/spec/adapter/publish_at_spec.rb +10 -10
- 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 +13 -13
- 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/middleware_spec.rb +112 -0
- data/spec/publish_spec.rb +20 -20
- data/spec/rider_spec.rb +7 -7
- data/spec/spec_helper.rb +2 -2
- data/spec/subscriber_spec.rb +98 -98
- data/spec/subscription_list_spec.rb +15 -15
- data/spec/subscription_spec.rb +17 -17
- data/spec/worker_spec.rb +30 -25
- metadata +7 -3
@@ -10,28 +10,28 @@ module QueueBus
|
|
10
10
|
|
11
11
|
it "should return from attributes" do
|
12
12
|
list = SubscriptionList.from_redis(mult)
|
13
|
-
list.size.
|
13
|
+
expect(list.size).to eq(2)
|
14
14
|
one = list.key("event_one")
|
15
15
|
two = list.key("event_two")
|
16
16
|
|
17
|
-
one.key.
|
18
|
-
one.key.
|
19
|
-
one.queue_name.
|
20
|
-
one.class_name.
|
21
|
-
one.matcher.filters.
|
17
|
+
expect(one.key).to eq("event_one")
|
18
|
+
expect(one.key).to eq("event_one")
|
19
|
+
expect(one.queue_name).to eq("default")
|
20
|
+
expect(one.class_name).to eq("MyClass")
|
21
|
+
expect(one.matcher.filters).to eq({"bus_event_type" => "event_one"})
|
22
22
|
|
23
|
-
two.key.
|
24
|
-
two.key.
|
25
|
-
two.queue_name.
|
26
|
-
two.class_name.
|
27
|
-
two.matcher.filters.
|
23
|
+
expect(two.key).to eq("event_two")
|
24
|
+
expect(two.key).to eq("event_two")
|
25
|
+
expect(two.queue_name).to eq("else")
|
26
|
+
expect(two.class_name).to eq("MyClass")
|
27
|
+
expect(two.matcher.filters).to eq({"bus_event_type" => "event_two"})
|
28
28
|
end
|
29
29
|
|
30
30
|
it "raises an error if a subscription key already exists" do
|
31
31
|
mult["event_two"]["key"] = "event_one"
|
32
32
|
|
33
|
-
|
34
|
-
.
|
33
|
+
expect { SubscriptionList.from_redis(mult) }
|
34
|
+
.to raise_error(RuntimeError)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -42,9 +42,9 @@ module QueueBus
|
|
42
42
|
list.add(Subscription.new("else_ok", "key2", "MyClass", {"bus_event_type" => "event_two"}))
|
43
43
|
|
44
44
|
hash = list.to_redis
|
45
|
-
hash.
|
45
|
+
expect(hash).to eq({ "key1" => {"queue_name" => "default", "key" => "key1", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_one"}},
|
46
46
|
"key2" => {"queue_name" => "else_ok", "key" => "key2", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_two"}}
|
47
|
-
}
|
47
|
+
})
|
48
48
|
|
49
49
|
end
|
50
50
|
end
|
data/spec/subscription_spec.rb
CHANGED
@@ -3,27 +3,27 @@ require 'spec_helper'
|
|
3
3
|
module QueueBus
|
4
4
|
describe Subscription do
|
5
5
|
it "should normalize the queue name" do
|
6
|
-
Subscription.new("test", "my_event", "MyClass", {}, nil).queue_name.
|
7
|
-
Subscription.new("tes t", "my_event", "MyClass", {}, nil).queue_name.
|
8
|
-
Subscription.new("t%s", "my_event", "MyClass", {}, nil).queue_name.
|
6
|
+
expect(Subscription.new("test", "my_event", "MyClass", {}, nil).queue_name).to eq("test")
|
7
|
+
expect(Subscription.new("tes t", "my_event", "MyClass", {}, nil).queue_name).to eq("tes_t")
|
8
|
+
expect(Subscription.new("t%s", "my_event", "MyClass", {}, nil).queue_name).to eq("t_s")
|
9
9
|
end
|
10
10
|
|
11
11
|
describe ".register" do
|
12
12
|
it "should take in args from dispatcher" do
|
13
13
|
executor = Proc.new { |attributes| }
|
14
14
|
sub = Subscription.register("queue_name", "mykey", "MyClass", {"bus_event_type" => "my_event"}, executor)
|
15
|
-
sub.send(:executor).
|
16
|
-
sub.matcher.filters.
|
17
|
-
sub.queue_name.
|
18
|
-
sub.key.
|
19
|
-
sub.class_name.
|
15
|
+
expect(sub.send(:executor)).to eq(executor)
|
16
|
+
expect(sub.matcher.filters).to eq({"bus_event_type" => "my_event"})
|
17
|
+
expect(sub.queue_name).to eq("queue_name")
|
18
|
+
expect(sub.key).to eq("mykey")
|
19
|
+
expect(sub.class_name).to eq("MyClass")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#execute!" do
|
24
24
|
it "should call the executor with the attributes" do
|
25
25
|
exec = Object.new
|
26
|
-
exec.
|
26
|
+
expect(exec).to receive(:call)
|
27
27
|
|
28
28
|
sub = Subscription.new("x", "y", "ClassName", {}, exec)
|
29
29
|
sub.execute!({"ok" => true})
|
@@ -33,19 +33,19 @@ module QueueBus
|
|
33
33
|
describe "#to_redis" do
|
34
34
|
it "should return what to store for this subscription" do
|
35
35
|
sub = Subscription.new("queue_one", "xyz", "ClassName", {"bus_event_type" => "my_event"}, nil)
|
36
|
-
sub.to_redis.
|
36
|
+
expect(sub.to_redis).to eq({"queue_name" => "queue_one", "key" => "xyz", "class" => "ClassName", "matcher" => {"bus_event_type" => "my_event"}})
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#matches?" do
|
41
41
|
it "should do pattern stuff" do
|
42
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "one").
|
43
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "onex").
|
44
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "^one.*$"}).matches?("bus_event_type" => "onex").
|
45
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.*"}).matches?("bus_event_type" => "onex").
|
46
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "onex").
|
47
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "one").
|
48
|
-
Subscription.new("x", "id", "ClassName", {"bus_event_type" => "\\"}).matches?("bus_event_type" => "one").
|
42
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "one")).to eq(true)
|
43
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one"}).matches?("bus_event_type" => "onex")).to eq(false)
|
44
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "^one.*$"}).matches?("bus_event_type" => "onex")).to eq(true)
|
45
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.*"}).matches?("bus_event_type" => "onex")).to eq(true)
|
46
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "onex")).to eq(true)
|
47
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "one.?"}).matches?("bus_event_type" => "one")).to eq(true)
|
48
|
+
expect(Subscription.new("x", "id", "ClassName", {"bus_event_type" => "\\"}).matches?("bus_event_type" => "one")).to eq(false)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
data/spec/worker_spec.rb
CHANGED
@@ -1,32 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'json'
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
describe QueueBus::Worker do
|
5
|
+
it "proxies to given class" do
|
6
|
+
hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
|
7
|
+
expect(QueueBus::Driver).to receive(:perform).with(hash)
|
8
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
9
|
+
end
|
10
|
+
|
11
|
+
it "uses an instance" do
|
12
|
+
hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
|
13
|
+
expect(QueueBus::Rider).to receive(:perform).with(hash)
|
14
|
+
QueueBus::Worker.new.perform(JSON.generate(hash))
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
QueueBus::Worker.
|
15
|
-
|
17
|
+
it "does not freak out if class not there anymore" do
|
18
|
+
hash = {"bus_class_proxy" => "QueueBus::BadClass", "ok" => true}
|
19
|
+
expect {
|
20
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
21
|
+
}.not_to raise_error
|
22
|
+
end
|
16
23
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
it "raises error if proxy raises error" do
|
25
|
+
hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
|
26
|
+
expect(QueueBus::Rider).to receive(:perform).with(hash).and_raise("rider crash")
|
27
|
+
expect {
|
28
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
29
|
+
}.to raise_error(RuntimeError, 'rider crash')
|
30
|
+
end
|
23
31
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
QueueBus::Worker.perform(JSON.generate(hash))
|
29
|
-
}.should raise_error
|
30
|
-
end
|
32
|
+
it "runs the middleware stack" do
|
33
|
+
hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
|
34
|
+
expect(QueueBus.worker_middleware_stack).to receive(:run).with(hash).and_yield
|
35
|
+
QueueBus::Worker.perform(JSON.generate(hash))
|
31
36
|
end
|
32
37
|
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.6.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:
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- ".rbenv-version"
|
93
93
|
- ".rspec"
|
94
94
|
- ".rvmrc"
|
95
|
+
- CHANGELOG.md
|
95
96
|
- Gemfile
|
96
97
|
- MIT-LICENSE
|
97
98
|
- README.mdown
|
@@ -107,6 +108,7 @@ files:
|
|
107
108
|
- lib/queue_bus/heartbeat.rb
|
108
109
|
- lib/queue_bus/local.rb
|
109
110
|
- lib/queue_bus/matcher.rb
|
111
|
+
- lib/queue_bus/middleware.rb
|
110
112
|
- lib/queue_bus/publisher.rb
|
111
113
|
- lib/queue_bus/publishing.rb
|
112
114
|
- lib/queue_bus/rider.rb
|
@@ -129,6 +131,7 @@ files:
|
|
129
131
|
- spec/heartbeat_spec.rb
|
130
132
|
- spec/integration_spec.rb
|
131
133
|
- spec/matcher_spec.rb
|
134
|
+
- spec/middleware_spec.rb
|
132
135
|
- spec/publish_spec.rb
|
133
136
|
- spec/publisher_spec.rb
|
134
137
|
- spec/rider_spec.rb
|
@@ -156,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
159
|
version: '0'
|
157
160
|
requirements: []
|
158
161
|
rubyforge_project: queue-bus
|
159
|
-
rubygems_version: 2.
|
162
|
+
rubygems_version: 2.7.6
|
160
163
|
signing_key:
|
161
164
|
specification_version: 4
|
162
165
|
summary: A simple event bus on top of background queues
|
@@ -171,6 +174,7 @@ test_files:
|
|
171
174
|
- spec/heartbeat_spec.rb
|
172
175
|
- spec/integration_spec.rb
|
173
176
|
- spec/matcher_spec.rb
|
177
|
+
- spec/middleware_spec.rb
|
174
178
|
- spec/publish_spec.rb
|
175
179
|
- spec/publisher_spec.rb
|
176
180
|
- spec/rider_spec.rb
|