queue-bus 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +21 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -2
- data/Rakefile +2 -0
- data/lib/queue-bus.rb +15 -12
- data/lib/queue_bus/adapters/base.rb +4 -2
- data/lib/queue_bus/adapters/data.rb +12 -11
- data/lib/queue_bus/application.rb +13 -15
- data/lib/queue_bus/dispatch.rb +14 -12
- data/lib/queue_bus/dispatchers.rb +12 -5
- data/lib/queue_bus/driver.rb +15 -10
- data/lib/queue_bus/heartbeat.rb +32 -30
- data/lib/queue_bus/local.rb +9 -9
- data/lib/queue_bus/matcher.rb +36 -27
- data/lib/queue_bus/publisher.rb +7 -5
- data/lib/queue_bus/publishing.rb +31 -24
- data/lib/queue_bus/rider.rb +26 -22
- data/lib/queue_bus/subscriber.rb +20 -14
- data/lib/queue_bus/subscription.rb +25 -15
- data/lib/queue_bus/subscription_list.rb +30 -12
- data/lib/queue_bus/task_manager.rb +18 -16
- data/lib/queue_bus/tasks.rb +20 -15
- data/lib/queue_bus/util.rb +11 -8
- data/lib/queue_bus/version.rb +3 -1
- data/lib/queue_bus/worker.rb +3 -2
- data/queue-bus.gemspec +19 -18
- data/spec/adapter/publish_at_spec.rb +28 -25
- data/spec/adapter/support.rb +7 -1
- data/spec/adapter_spec.rb +4 -2
- data/spec/application_spec.rb +97 -97
- data/spec/dispatch_spec.rb +48 -51
- data/spec/driver_spec.rb +60 -58
- data/spec/heartbeat_spec.rb +26 -24
- data/spec/integration_spec.rb +41 -40
- data/spec/matcher_spec.rb +104 -102
- data/spec/publish_spec.rb +46 -46
- data/spec/publisher_spec.rb +3 -1
- data/spec/rider_spec.rb +16 -14
- data/spec/spec_helper.rb +2 -2
- data/spec/subscriber_spec.rb +227 -227
- data/spec/subscription_list_spec.rb +31 -31
- data/spec/subscription_spec.rb +37 -36
- data/spec/worker_spec.rb +17 -15
- metadata +7 -6
@@ -1,52 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe SubscriptionList do
|
5
|
-
describe
|
7
|
+
describe '.from_redis' do
|
6
8
|
let(:mult) do
|
7
|
-
{
|
8
|
-
|
9
|
+
{ 'event_one' => { 'class' => 'MyClass', 'queue_name' => 'default', 'key' => 'event_one', 'matcher' => { 'bus_event_type' => 'event_one' } },
|
10
|
+
'event_two' => { 'class' => 'MyClass', 'queue_name' => 'else', 'key' => 'event_two', 'matcher' => { 'bus_event_type' => 'event_two' } } }
|
9
11
|
end
|
10
12
|
|
11
|
-
it
|
13
|
+
it 'should return from attributes' do
|
12
14
|
list = SubscriptionList.from_redis(mult)
|
13
15
|
expect(list.size).to eq(2)
|
14
|
-
one = list.key(
|
15
|
-
two = list.key(
|
16
|
-
|
17
|
-
expect(one.key).to eq(
|
18
|
-
expect(one.key).to eq(
|
19
|
-
expect(one.queue_name).to eq(
|
20
|
-
expect(one.class_name).to eq(
|
21
|
-
expect(one.matcher.filters).to eq(
|
22
|
-
|
23
|
-
expect(two.key).to eq(
|
24
|
-
expect(two.key).to eq(
|
25
|
-
expect(two.queue_name).to eq(
|
26
|
-
expect(two.class_name).to eq(
|
27
|
-
expect(two.matcher.filters).to eq(
|
16
|
+
one = list.key('event_one')
|
17
|
+
two = list.key('event_two')
|
18
|
+
|
19
|
+
expect(one.key).to eq('event_one')
|
20
|
+
expect(one.key).to eq('event_one')
|
21
|
+
expect(one.queue_name).to eq('default')
|
22
|
+
expect(one.class_name).to eq('MyClass')
|
23
|
+
expect(one.matcher.filters).to eq('bus_event_type' => 'event_one')
|
24
|
+
|
25
|
+
expect(two.key).to eq('event_two')
|
26
|
+
expect(two.key).to eq('event_two')
|
27
|
+
expect(two.queue_name).to eq('else')
|
28
|
+
expect(two.class_name).to eq('MyClass')
|
29
|
+
expect(two.matcher.filters).to eq('bus_event_type' => 'event_two')
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
31
|
-
mult[
|
32
|
+
it 'raises an error if a subscription key already exists' do
|
33
|
+
mult['event_two']['key'] = 'event_one'
|
32
34
|
|
33
35
|
expect { SubscriptionList.from_redis(mult) }
|
34
36
|
.to raise_error(RuntimeError)
|
35
37
|
end
|
36
38
|
end
|
37
|
-
|
38
|
-
describe
|
39
|
-
it
|
39
|
+
|
40
|
+
describe '#to_redis' do
|
41
|
+
it 'should generate what to store' do
|
40
42
|
list = SubscriptionList.new
|
41
|
-
list.add(Subscription.new(
|
42
|
-
list.add(Subscription.new(
|
43
|
-
|
43
|
+
list.add(Subscription.new('default', 'key1', 'MyClass', 'bus_event_type' => 'event_one'))
|
44
|
+
list.add(Subscription.new('else_ok', 'key2', 'MyClass', 'bus_event_type' => 'event_two'))
|
45
|
+
|
44
46
|
hash = list.to_redis
|
45
|
-
expect(hash).to eq(
|
46
|
-
|
47
|
-
})
|
48
|
-
|
47
|
+
expect(hash).to eq('key1' => { 'queue_name' => 'default', 'key' => 'key1', 'class' => 'MyClass', 'matcher' => { 'bus_event_type' => 'event_one' } },
|
48
|
+
'key2' => { 'queue_name' => 'else_ok', 'key' => 'key2', 'class' => 'MyClass', 'matcher' => { 'bus_event_type' => 'event_two' } })
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
52
|
+
end
|
data/spec/subscription_spec.rb
CHANGED
@@ -1,53 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module QueueBus
|
4
6
|
describe Subscription do
|
5
|
-
it
|
6
|
-
expect(Subscription.new(
|
7
|
-
expect(Subscription.new(
|
8
|
-
expect(Subscription.new(
|
7
|
+
it 'should normalize the queue name' do
|
8
|
+
expect(Subscription.new('test', 'my_event', 'MyClass', {}, nil).queue_name).to eq('test')
|
9
|
+
expect(Subscription.new('tes t', 'my_event', 'MyClass', {}, nil).queue_name).to eq('tes_t')
|
10
|
+
expect(Subscription.new('t%s', 'my_event', 'MyClass', {}, nil).queue_name).to eq('t_s')
|
9
11
|
end
|
10
|
-
|
11
|
-
describe
|
12
|
-
it
|
13
|
-
executor =
|
14
|
-
sub = Subscription.register(
|
12
|
+
|
13
|
+
describe '.register' do
|
14
|
+
it 'should take in args from dispatcher' do
|
15
|
+
executor = proc { |attributes| }
|
16
|
+
sub = Subscription.register('queue_name', 'mykey', 'MyClass', { 'bus_event_type' => 'my_event' }, executor)
|
15
17
|
expect(sub.send(:executor)).to eq(executor)
|
16
|
-
expect(sub.matcher.filters).to eq(
|
17
|
-
expect(sub.queue_name).to eq(
|
18
|
-
expect(sub.key).to eq(
|
19
|
-
expect(sub.class_name).to eq(
|
18
|
+
expect(sub.matcher.filters).to eq('bus_event_type' => 'my_event')
|
19
|
+
expect(sub.queue_name).to eq('queue_name')
|
20
|
+
expect(sub.key).to eq('mykey')
|
21
|
+
expect(sub.class_name).to eq('MyClass')
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
23
|
-
describe
|
24
|
-
it
|
24
|
+
|
25
|
+
describe '#execute!' do
|
26
|
+
it 'should call the executor with the attributes' do
|
25
27
|
exec = Object.new
|
26
28
|
expect(exec).to receive(:call)
|
27
|
-
|
28
|
-
sub = Subscription.new(
|
29
|
-
sub.execute!(
|
29
|
+
|
30
|
+
sub = Subscription.new('x', 'y', 'ClassName', {}, exec)
|
31
|
+
sub.execute!('ok' => true)
|
30
32
|
end
|
31
33
|
end
|
32
|
-
|
33
|
-
describe
|
34
|
-
it
|
35
|
-
sub = Subscription.new(
|
36
|
-
expect(sub.to_redis).to eq(
|
34
|
+
|
35
|
+
describe '#to_redis' do
|
36
|
+
it 'should return what to store for this subscription' do
|
37
|
+
sub = Subscription.new('queue_one', 'xyz', 'ClassName', { 'bus_event_type' => 'my_event' }, nil)
|
38
|
+
expect(sub.to_redis).to eq('queue_name' => 'queue_one', 'key' => 'xyz', 'class' => 'ClassName', 'matcher' => { 'bus_event_type' => 'my_event' })
|
37
39
|
end
|
38
40
|
end
|
39
|
-
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
expect(Subscription.new(
|
43
|
-
expect(Subscription.new(
|
44
|
-
expect(Subscription.new(
|
45
|
-
expect(Subscription.new(
|
46
|
-
expect(Subscription.new(
|
47
|
-
expect(Subscription.new(
|
48
|
-
expect(Subscription.new(
|
41
|
+
|
42
|
+
describe '#matches?' do
|
43
|
+
it 'should do pattern stuff' do
|
44
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one').matches?('bus_event_type' => 'one')).to eq(true)
|
45
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one').matches?('bus_event_type' => 'onex')).to eq(false)
|
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' => 'onex')).to eq(true)
|
48
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one.?').matches?('bus_event_type' => 'onex')).to eq(true)
|
49
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => 'one.?').matches?('bus_event_type' => 'one')).to eq(true)
|
50
|
+
expect(Subscription.new('x', 'id', 'ClassName', 'bus_event_type' => '\\').matches?('bus_event_type' => 'one')).to eq(false)
|
49
51
|
end
|
50
52
|
end
|
51
|
-
|
52
53
|
end
|
53
|
-
end
|
54
|
+
end
|
data/spec/worker_spec.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'json'
|
3
5
|
|
4
6
|
describe QueueBus::Worker do
|
5
|
-
it
|
6
|
-
hash = {
|
7
|
+
it 'proxies to given class' do
|
8
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Driver', 'ok' => true }
|
7
9
|
expect(QueueBus::Driver).to receive(:perform).with(hash)
|
8
10
|
QueueBus::Worker.perform(JSON.generate(hash))
|
9
11
|
end
|
10
12
|
|
11
|
-
it
|
12
|
-
hash = {
|
13
|
+
it 'uses an instance' do
|
14
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Rider', 'ok' => true }
|
13
15
|
expect(QueueBus::Rider).to receive(:perform).with(hash)
|
14
16
|
QueueBus::Worker.new.perform(JSON.generate(hash))
|
15
17
|
end
|
16
18
|
|
17
|
-
it
|
18
|
-
hash = {
|
19
|
-
expect
|
19
|
+
it 'does not freak out if class not there anymore' do
|
20
|
+
hash = { 'bus_class_proxy' => 'QueueBus::BadClass', 'ok' => true }
|
21
|
+
expect do
|
20
22
|
QueueBus::Worker.perform(JSON.generate(hash))
|
21
|
-
|
23
|
+
end.not_to raise_error
|
22
24
|
end
|
23
25
|
|
24
|
-
it
|
25
|
-
hash = {
|
26
|
-
expect(QueueBus::Rider).to receive(:perform).with(hash).and_raise(
|
27
|
-
expect
|
26
|
+
it 'raises error if proxy raises error' do
|
27
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Rider', 'ok' => true }
|
28
|
+
expect(QueueBus::Rider).to receive(:perform).with(hash).and_raise('rider crash')
|
29
|
+
expect do
|
28
30
|
QueueBus::Worker.perform(JSON.generate(hash))
|
29
|
-
|
31
|
+
end.to raise_error(RuntimeError, 'rider crash')
|
30
32
|
end
|
31
33
|
|
32
|
-
it
|
33
|
-
hash = {
|
34
|
+
it 'runs the middleware stack' do
|
35
|
+
hash = { 'bus_class_proxy' => 'QueueBus::Driver', 'ok' => true }
|
34
36
|
expect(QueueBus.worker_middleware_stack).to receive(:run).with(hash).and_yield
|
35
37
|
QueueBus::Worker.perform(JSON.generate(hash))
|
36
38
|
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.
|
4
|
+
version: 0.9.1
|
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: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: json_pure
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: timecop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -102,6 +102,7 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
+
- ".circleci/config.yml"
|
105
106
|
- ".gitignore"
|
106
107
|
- ".rbenv-version"
|
107
108
|
- ".rspec"
|