queue-bus 0.8.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +21 -0
  3. data/CHANGELOG.md +31 -0
  4. data/Gemfile +4 -2
  5. data/README.mdown +15 -3
  6. data/Rakefile +2 -0
  7. data/lib/queue-bus.rb +16 -12
  8. data/lib/queue_bus/adapters/base.rb +4 -2
  9. data/lib/queue_bus/adapters/data.rb +12 -11
  10. data/lib/queue_bus/application.rb +24 -16
  11. data/lib/queue_bus/config.rb +23 -2
  12. data/lib/queue_bus/dispatch.rb +14 -12
  13. data/lib/queue_bus/dispatchers.rb +12 -5
  14. data/lib/queue_bus/driver.rb +15 -10
  15. data/lib/queue_bus/heartbeat.rb +32 -30
  16. data/lib/queue_bus/local.rb +9 -9
  17. data/lib/queue_bus/matcher.rb +36 -27
  18. data/lib/queue_bus/publisher.rb +7 -5
  19. data/lib/queue_bus/publishing.rb +32 -24
  20. data/lib/queue_bus/rider.rb +26 -22
  21. data/lib/queue_bus/subscriber.rb +20 -14
  22. data/lib/queue_bus/subscription.rb +25 -15
  23. data/lib/queue_bus/subscription_list.rb +30 -12
  24. data/lib/queue_bus/task_manager.rb +25 -16
  25. data/lib/queue_bus/tasks.rb +35 -11
  26. data/lib/queue_bus/util.rb +11 -8
  27. data/lib/queue_bus/version.rb +3 -1
  28. data/lib/queue_bus/worker.rb +3 -2
  29. data/queue-bus.gemspec +19 -18
  30. data/spec/adapter/publish_at_spec.rb +28 -25
  31. data/spec/adapter/support.rb +7 -1
  32. data/spec/adapter_spec.rb +4 -2
  33. data/spec/application_spec.rb +138 -96
  34. data/spec/config_spec.rb +36 -0
  35. data/spec/dispatch_spec.rb +48 -51
  36. data/spec/driver_spec.rb +60 -58
  37. data/spec/heartbeat_spec.rb +26 -24
  38. data/spec/integration_spec.rb +41 -40
  39. data/spec/matcher_spec.rb +104 -102
  40. data/spec/publish_spec.rb +68 -46
  41. data/spec/publisher_spec.rb +3 -1
  42. data/spec/rider_spec.rb +16 -14
  43. data/spec/spec_helper.rb +2 -2
  44. data/spec/subscriber_spec.rb +227 -227
  45. data/spec/subscription_list_spec.rb +57 -31
  46. data/spec/subscription_spec.rb +37 -36
  47. data/spec/worker_spec.rb +17 -15
  48. metadata +12 -10
@@ -1,52 +1,78 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe SubscriptionList do
5
- describe ".from_redis" do
7
+ describe '.from_redis' do
6
8
  let(:mult) do
7
- {"event_one" => {"class" => "MyClass", "queue_name" => "default", "key" => "event_one", "matcher" => {"bus_event_type" => "event_one"}},
8
- "event_two" => {"class" => "MyClass", "queue_name" => "else", "key" => "event_two", "matcher" => {"bus_event_type" => "event_two"}}}
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 "should return from attributes" do
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("event_one")
15
- two = list.key("event_two")
16
-
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
-
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"})
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 "raises an error if a subscription key already exists" do
31
- mult["event_two"]["key"] = "event_one"
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 "#to_redis" do
39
- it "should generate what to store" do
39
+
40
+ describe '#to_redis' do
41
+ it 'should generate what to store' do
40
42
  list = SubscriptionList.new
41
- list.add(Subscription.new("default", "key1", "MyClass", {"bus_event_type" => "event_one"}))
42
- list.add(Subscription.new("else_ok", "key2", "MyClass", {"bus_event_type" => "event_two"}))
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({ "key1" => {"queue_name" => "default", "key" => "key1", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_one"}},
46
- "key2" => {"queue_name" => "else_ok", "key" => "key2", "class" => "MyClass", "matcher" => {"bus_event_type" => "event_two"}}
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
+ end
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
49
75
  end
50
76
  end
51
77
  end
52
- end
78
+ end
@@ -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 "should normalize the queue name" do
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")
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 ".register" do
12
- it "should take in args from dispatcher" do
13
- executor = Proc.new { |attributes| }
14
- sub = Subscription.register("queue_name", "mykey", "MyClass", {"bus_event_type" => "my_event"}, executor)
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({"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")
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 "#execute!" do
24
- it "should call the executor with the attributes" do
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("x", "y", "ClassName", {}, exec)
29
- sub.execute!({"ok" => true})
29
+
30
+ sub = Subscription.new('x', 'y', 'ClassName', {}, exec)
31
+ sub.execute!('ok' => true)
30
32
  end
31
33
  end
32
-
33
- describe "#to_redis" do
34
- it "should return what to store for this subscription" do
35
- sub = Subscription.new("queue_one", "xyz", "ClassName", {"bus_event_type" => "my_event"}, nil)
36
- expect(sub.to_redis).to eq({"queue_name" => "queue_one", "key" => "xyz", "class" => "ClassName", "matcher" => {"bus_event_type" => "my_event"}})
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 "#matches?" do
41
- it "should do pattern stuff" do
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)
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 "proxies to given class" do
6
- hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
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 "uses an instance" do
12
- hash = {"bus_class_proxy" => "QueueBus::Rider", "ok" => true}
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 "does not freak out if class not there anymore" do
18
- hash = {"bus_class_proxy" => "QueueBus::BadClass", "ok" => true}
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
- }.not_to raise_error
23
+ end.not_to raise_error
22
24
  end
23
25
 
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 {
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
- }.to raise_error(RuntimeError, 'rider crash')
31
+ end.to raise_error(RuntimeError, 'rider crash')
30
32
  end
31
33
 
32
- it "runs the middleware stack" do
33
- hash = {"bus_class_proxy" => "QueueBus::Driver", "ok" => true}
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.8.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Leonard
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-21 00:00:00.000000000 Z
11
+ date: 2021-06-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: rspec
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: timecop
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: json_pure
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: rubocop
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"
@@ -158,7 +159,7 @@ files:
158
159
  homepage: ''
159
160
  licenses: []
160
161
  metadata: {}
161
- post_install_message:
162
+ post_install_message:
162
163
  rdoc_options: []
163
164
  require_paths:
164
165
  - lib
@@ -173,8 +174,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
174
  - !ruby/object:Gem::Version
174
175
  version: '0'
175
176
  requirements: []
176
- rubygems_version: 3.0.3
177
- signing_key:
177
+ rubyforge_project: queue-bus
178
+ rubygems_version: 2.7.6.2
179
+ signing_key:
178
180
  specification_version: 4
179
181
  summary: A simple event bus on top of background queues
180
182
  test_files: