sidekiq-bus 0.8.1 → 0.8.2

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
  SHA1:
3
- metadata.gz: a863bbad91a600acef85ae8edef094d7b62fef2c
4
- data.tar.gz: b190d70f8670247b800141aaa3d7f56860e6f2f4
3
+ metadata.gz: 2c633c91c5b55a5e08ec80f73ee6a174df07d59c
4
+ data.tar.gz: '00095d6bcdc1407137cab9051990b91f359df304'
5
5
  SHA512:
6
- metadata.gz: a5394ae7f51b10a9bd13b64d28aec02e9199b2f2773314d91330cee471769f51c3680974ae2c9056deeb68185ebc529156343e31089838ed8ea0e9c59d0f9736
7
- data.tar.gz: 8c676a81ff6cf08a321712aa2fab208247fc88e453ba3eb576248932588e4cc528fc9d7c7779c60560bde0e972e17c257f277ad3401dad880a888ac97d12db36
6
+ metadata.gz: a4dcb3d6a379ceda40fe1da42c6cdb00662b85f37bbfcf9010ed7303883d8e44a9f43f9ab9c587793503ce4ade15a09f1c23cbdd6ec07ae5f4d85af0ce8ced04
7
+ data.tar.gz: 2631baff2bc6724686516f34cc04955fef78884228566f961b2f51dd069130bf67c65a562200299e833b241d8ed18c6e7a17636768bfd6310d318de1c8997c0f
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ### [0.8.2] - 2019-08-06
10
+
11
+ ### Fixed
12
+ - Schedule now uses cron format to schedule heartbeat. The "every: 1min" format was causing multiple heartbeats to fire in the same minute if there were multiple sidekiq processes with the dynamic setting turned off (which is default).
13
+
9
14
  ### [0.8.1] - 2019-08-05
10
15
 
11
16
  ### Fixed
@@ -57,7 +57,7 @@ module QueueBus
57
57
  def set_schedule(queue_name)
58
58
  ::Sidekiq.set_schedule(
59
59
  'sidekiqbus_heartbeat',
60
- every: '1min',
60
+ cron: '0 * * * * *', # Runs every minute
61
61
  class: ::QueueBus::Worker.name,
62
62
  args: [
63
63
  ::QueueBus::Util.encode('bus_class_proxy' => ::QueueBus::Heartbeat.name)
@@ -1,18 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SidekiqBus
2
4
  module Middleware
3
5
  module Client
4
-
5
6
  # ensure sidekiq will retry jobs even when they are enqueued via other adapters
6
7
  class Retry
7
- def call(worker_class, job, queue, redis_pool)
8
- if job['class'] == 'QueueBus::Worker'
9
- job['retry'] = true unless job.has_key?('retry')
10
- job['backtrace'] = true unless job.has_key?('backtrace')
11
- end
12
- yield
13
- end
8
+ def call(_worker_class, job, _queue, _redis_pool)
9
+ if job['class'] == 'QueueBus::Worker'
10
+ job['retry'] = true unless job.key?('retry')
11
+ job['backtrace'] = true unless job.key?('backtrace')
12
+ end
13
+ yield
14
+ end
14
15
  end
15
-
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # require 'sidekiq_bus/tasks'
2
4
  # will give you these tasks
3
5
 
4
- require "queue_bus/tasks"
6
+ require 'queue_bus/tasks'
5
7
 
6
8
  namespace :queuebus do
7
-
8
9
  # Preload app files if this is Rails
9
10
  task :preload do
10
- require "sidekiq"
11
+ require 'sidekiq'
11
12
  end
12
-
13
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SidekiqBus
2
- VERSION = "0.8.1"
4
+ VERSION = '0.8.2'
3
5
  end
@@ -1,15 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
- if Sidekiq::VERSION < '4'
3
- require 'celluloid'
4
- end
4
+ require 'celluloid' if Sidekiq::VERSION < '4'
5
5
  require 'sidekiq/scheduled'
6
6
 
7
- describe "Sidekiq Integration" do
8
- describe "Happy Path" do
7
+ describe 'Sidekiq Integration' do
8
+ describe 'Happy Path' do
9
9
  before(:each) do
10
10
  Sidekiq::Testing.fake!
11
- QueueBus.dispatch("r1") do
12
- subscribe "event_name" do |attributes|
11
+ QueueBus.dispatch('r1') do
12
+ subscribe 'event_name' do |attributes|
13
13
  QueueBus::Runner1.run(attributes)
14
14
  end
15
15
  end
@@ -17,11 +17,11 @@ describe "Sidekiq Integration" do
17
17
  QueueBus::TaskManager.new(false).subscribe!
18
18
  end
19
19
 
20
- it "should publish and receive" do
20
+ it 'should publish and receive' do
21
21
  Sidekiq::Testing.fake!
22
22
  expect(QueueBus::Runner1.value).to eq(0)
23
23
 
24
- QueueBus.publish("event_name", "ok" => true)
24
+ QueueBus.publish('event_name', 'ok' => true)
25
25
  expect(QueueBus::Runner1.value).to eq(0)
26
26
 
27
27
  QueueBus::Worker.perform_one
@@ -33,58 +33,59 @@ describe "Sidekiq Integration" do
33
33
  expect(QueueBus::Runner1.value).to eq(1)
34
34
  end
35
35
 
36
- it "should publish and receive" do
36
+ it 'should publish and receive' do
37
37
  Sidekiq::Testing.inline!
38
38
  expect(QueueBus::Runner1.value).to eq(0)
39
39
 
40
- QueueBus.publish("event_name", "ok" => true)
40
+ QueueBus.publish('event_name', 'ok' => true)
41
41
  expect(QueueBus::Runner1.value).to eq(1)
42
42
  end
43
-
44
43
  end
45
44
 
46
- describe "Delayed Publishing" do
45
+ describe 'Delayed Publishing' do
47
46
  before(:each) do
48
47
  Timecop.freeze(now)
49
- allow(QueueBus).to receive(:generate_uuid).and_return("idfhlkj")
48
+ allow(QueueBus).to receive(:generate_uuid).and_return('idfhlkj')
50
49
  end
51
50
  after(:each) do
52
51
  Timecop.return
53
52
  end
54
- let(:delayed_attrs) { {"bus_delayed_until" => future.to_i,
55
- "bus_id" => "#{now.to_i}-idfhlkj",
56
- "bus_app_hostname" => `hostname 2>&1`.strip.sub(/.local/,'')} }
53
+ let(:delayed_attrs) do
54
+ { 'bus_delayed_until' => future.to_i,
55
+ 'bus_id' => "#{now.to_i}-idfhlkj",
56
+ 'bus_app_hostname' => Socket.gethostname }
57
+ end
57
58
 
58
- let(:bus_attrs) { delayed_attrs.merge({"bus_published_at" => worktime.to_i})}
59
- let(:now) { Time.parse("01/01/2013 5:00")}
59
+ let(:bus_attrs) { delayed_attrs.merge('bus_published_at' => worktime.to_i) }
60
+ let(:now) { Time.parse('01/01/2013 5:00') }
60
61
  let(:future) { Time.at(now.to_i + 60) }
61
- let(:worktime) {Time.at(future.to_i + 1)}
62
+ let(:worktime) { Time.at(future.to_i + 1) }
62
63
 
63
- it "should add it to Redis" do
64
- hash = {:one => 1, "two" => "here", "id" => 12 }
65
- event_name = "event_name"
64
+ it 'should add it to Redis' do
65
+ hash = { :one => 1, 'two' => 'here', 'id' => 12 }
66
+ event_name = 'event_name'
66
67
  QueueBus.publish_at(future, event_name, hash)
67
68
 
68
- val = QueueBus.redis { |redis| redis.zrange("schedule", 0, 1) }.first
69
+ val = QueueBus.redis { |redis| redis.zrange('schedule', 0, 1) }.first
69
70
 
70
71
  hash = JSON.parse(val)
71
72
 
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")
73
+ expect(hash['class']).to eq('QueueBus::Worker')
74
+ expect(hash['args'].size).to eq(1)
75
+ 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))
76
+ expect(hash['queue']).to eq('bus_incoming')
76
77
  end
77
78
 
78
- it "should move it to the real queue when processing" do
79
- hash = {:one => 1, "two" => "here", "id" => 12 }
80
- event_name = "event_name"
79
+ it 'should move it to the real queue when processing' do
80
+ hash = { :one => 1, 'two' => 'here', 'id' => 12 }
81
+ event_name = 'event_name'
81
82
 
82
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
83
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
83
84
  expect(val).to eq(nil)
84
85
 
85
86
  QueueBus.publish_at(future, event_name, hash)
86
87
 
87
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
88
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
88
89
  expect(val).to eq(nil) # nothing really added
89
90
 
90
91
  if Sidekiq::VERSION < '4'
@@ -93,7 +94,7 @@ describe "Sidekiq Integration" do
93
94
  Sidekiq::Scheduled::Poller.new.enqueue
94
95
  end
95
96
 
96
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
97
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
97
98
  expect(val).to eq(nil) # nothing added yet
98
99
 
99
100
  # process scheduler in future
@@ -104,21 +105,20 @@ describe "Sidekiq Integration" do
104
105
  Sidekiq::Scheduled::Poller.new.enqueue
105
106
  end
106
107
 
107
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
108
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
108
109
  hash = JSON.parse(val)
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))
110
+ expect(hash['class']).to eq('QueueBus::Worker')
111
+ expect(hash['args'].size).to eq(1)
112
+ 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
113
 
113
- QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
114
+ QueueBus::Publisher.perform(JSON.parse(hash['args'].first))
114
115
 
115
- val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
116
- hash = JSON.parse(val)
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))
116
+ val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
117
+ hash = JSON.parse(val)
118
+ expect(hash['class']).to eq('QueueBus::Worker')
119
+ expect(hash['args'].size).to eq(1)
120
+ 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
121
  end
121
122
  end
122
-
123
123
  end
124
124
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sidekiq-bus'
2
4
 
3
5
  def reset_test_adapter
@@ -40,7 +40,8 @@ describe 'adapter is set' do
40
40
 
41
41
  shared_examples 'a scheduled heartbeat' do
42
42
  it 'has the schedule for every minute' do
43
- expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['every']).to eq '1min'
43
+ expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['every']).to be_nil
44
+ expect(Sidekiq.get_schedule('sidekiqbus_heartbeat')['cron']).to eq '0 * * * * *'
44
45
  end
45
46
 
46
47
  it 'has scheduled the queue bus worker' do
@@ -1,151 +1,151 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module QueueBus
4
6
  describe Application do
5
- describe ".all" do
6
- it "should return empty array when none" do
7
+ describe '.all' do
8
+ it 'should return empty array when none' do
7
9
  expect(Application.all).to eq([])
8
10
  end
9
- it "should return registered applications when there are some" do
10
- Application.new("One").subscribe(test_list(test_sub("fdksjh")))
11
- Application.new("Two").subscribe(test_list(test_sub("fdklhf")))
12
- Application.new("Three").subscribe(test_list(test_sub("fkld")))
11
+ it 'should return registered applications when there are some' do
12
+ Application.new('One').subscribe(test_list(test_sub('fdksjh')))
13
+ Application.new('Two').subscribe(test_list(test_sub('fdklhf')))
14
+ Application.new('Three').subscribe(test_list(test_sub('fkld')))
13
15
 
14
- expect(Application.all.collect(&:app_key)).to match_array(["one", "two", "three"])
16
+ expect(Application.all.collect(&:app_key)).to match_array(%w[one two three])
15
17
 
16
- Application.new("two").unsubscribe
17
- expect(Application.all.collect(&:app_key)).to match_array(["one", "three"])
18
+ Application.new('two').unsubscribe
19
+ expect(Application.all.collect(&:app_key)).to match_array(%w[one three])
18
20
  end
19
21
  end
20
22
 
21
- describe ".new" do
22
- it "should have a key" do
23
- expect(Application.new("something").app_key).to eq("something")
23
+ describe '.new' do
24
+ it 'should have a key' do
25
+ expect(Application.new('something').app_key).to eq('something')
24
26
 
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")
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
+ expect(Application.new('some_thing').app_key).to eq('some_thing')
30
+ expect(Application.new('Some Thing').app_key).to eq('some_thing')
29
31
  end
30
32
 
31
- it "should raise an error if not valid" do
32
- expect {
33
- Application.new("")
34
- }.to raise_error("Invalid application name")
33
+ it 'should raise an error if not valid' do
34
+ expect do
35
+ Application.new('')
36
+ end.to raise_error('Invalid application name')
35
37
 
36
- expect {
38
+ expect do
37
39
  Application.new(nil)
38
- }.to raise_error("Invalid application name")
40
+ end.to raise_error('Invalid application name')
39
41
 
40
- expect {
41
- Application.new("/")
42
- }.to raise_error("Invalid application name")
42
+ expect do
43
+ Application.new('/')
44
+ end.to raise_error('Invalid application name')
43
45
  end
44
46
  end
45
47
 
46
- describe "#read_redis_hash" do
47
- it "should handle old and new values" do
48
-
49
- QueueBus.redis { |redis| redis.hset("bus_app:myapp", "new_one", QueueBus::Util.encode("queue_name" => "x", "bus_event_type" => "event_name") ) }
50
- QueueBus.redis { |redis| redis.hset("bus_app:myapp", "old_one", "oldqueue_name") }
51
- app = Application.new("myapp")
48
+ describe '#read_redis_hash' do
49
+ it 'should handle old and new values' do
50
+ QueueBus.redis { |redis| redis.hset('bus_app:myapp', 'new_one', QueueBus::Util.encode('queue_name' => 'x', 'bus_event_type' => 'event_name')) }
51
+ QueueBus.redis { |redis| redis.hset('bus_app:myapp', 'old_one', 'oldqueue_name') }
52
+ app = Application.new('myapp')
52
53
  val = app.send(:read_redis_hash)
53
- expect(val).to eq({"new_one" => {"queue_name" => "x", "bus_event_type" => "event_name"}, "old_one" => "oldqueue_name"})
54
+ expect(val).to eq('new_one' => { 'queue_name' => 'x', 'bus_event_type' => 'event_name' }, 'old_one' => 'oldqueue_name')
54
55
  end
55
56
  end
56
57
 
57
- describe "#subscribe" do
58
- let(:sub1) { test_sub("event_one", "default") }
59
- let(:sub2) { test_sub("event_two", "default") }
60
- let(:sub3) { test_sub("event_three", "other") }
61
- it "should add array to redis" do
62
- expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
63
- Application.new("myapp").subscribe(test_list(sub1, sub2))
64
-
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"])
58
+ describe '#subscribe' do
59
+ let(:sub1) { test_sub('event_one', 'default') }
60
+ let(:sub2) { test_sub('event_two', 'default') }
61
+ let(:sub3) { test_sub('event_three', 'other') }
62
+ it 'should add array to redis' do
63
+ expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
64
+ Application.new('myapp').subscribe(test_list(sub1, sub2))
65
+
66
+ 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"}}',
67
+ 'event_one' => '{"queue_name":"default","key":"event_one","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_one"}}')
68
+ expect(QueueBus.redis { |redis| redis.hkeys('bus_app:myapp') }).to match_array(%w[event_one event_two])
69
+ expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to match_array(['myapp'])
69
70
  end
70
- it "should add string to redis" do
71
- expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
72
- Application.new("myapp").subscribe(test_list(sub1))
71
+ it 'should add string to redis' do
72
+ expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
73
+ Application.new('myapp').subscribe(test_list(sub1))
73
74
 
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"])
75
+ 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"}}')
76
+ expect(QueueBus.redis { |redis| redis.hkeys('bus_app:myapp') }).to match_array(['event_one'])
77
+ expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to match_array(['myapp'])
77
78
  end
78
- it "should multiple queues to redis" do
79
- expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
80
- Application.new("myapp").subscribe(test_list(sub1, sub2, sub3))
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"])
79
+ it 'should multiple queues to redis' do
80
+ expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
81
+ Application.new('myapp').subscribe(test_list(sub1, sub2, sub3))
82
+ 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"}}',
83
+ 'event_three' => '{"queue_name":"other","key":"event_three","class":"::QueueBus::Rider","matcher":{"bus_event_type":"event_three"}}')
84
+ expect(QueueBus.redis { |redis| redis.hkeys('bus_app:myapp') }).to match_array(%w[event_three event_two event_one])
85
+ expect(QueueBus.redis { |redis| redis.smembers('bus_apps') }).to match_array(['myapp'])
85
86
  end
86
87
 
87
- it "should do nothing if nil or empty" do
88
-
89
- expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
88
+ it 'should do nothing if nil or empty' do
89
+ expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
90
90
 
91
- Application.new("myapp").subscribe(nil)
92
- expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
91
+ Application.new('myapp').subscribe(nil)
92
+ expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
93
93
 
94
- Application.new("myapp").subscribe([])
95
- expect(QueueBus.redis { |redis| redis.get("bus_app:myapp") }).to be_nil
94
+ Application.new('myapp').subscribe([])
95
+ expect(QueueBus.redis { |redis| redis.get('bus_app:myapp') }).to be_nil
96
96
  end
97
97
 
98
- it "should call unsubscribe" do
99
- app = Application.new("myapp")
98
+ it 'should call unsubscribe' do
99
+ app = Application.new('myapp')
100
100
  expect(app).to receive(:unsubscribe)
101
101
  app.subscribe([])
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
+ 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') }
110
110
 
111
- Application.new("myapp").unsubscribe
111
+ Application.new('myapp').unsubscribe
112
112
 
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
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
- describe "#subscription_matches" do
119
- it "should return if it is there" do
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([])
118
+ describe '#subscription_matches' do
119
+ it 'should return if it is there' do
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
- subs = test_list(test_sub("one_x"), test_sub("one_y"), test_sub("one"), test_sub("two"))
123
- Application.new("myapp").subscribe(subs)
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([])
122
+ subs = test_list(test_sub('one_x'), test_sub('one_y'), test_sub('one'), test_sub('two'))
123
+ Application.new('myapp').subscribe(subs)
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
- 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"]])
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
- it "should handle * wildcards" do
131
- subs = test_list(test_sub("one.+"), test_sub("one"), test_sub("one_.*"), test_sub("two"))
132
- Application.new("myapp").subscribe(subs)
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([])
130
+ it 'should handle * wildcards' do
131
+ subs = test_list(test_sub('one.+'), test_sub('one'), test_sub('one_.*'), test_sub('two'))
132
+ Application.new('myapp').subscribe(subs)
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
- 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"]])
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
- it "should handle actual regular expressions" do
141
- subs = test_list(test_sub(/one.+/), test_sub("one"), test_sub(/one_.*/), test_sub("two"))
142
- Application.new("myapp").subscribe(subs)
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([])
140
+ it 'should handle actual regular expressions' do
141
+ subs = test_list(test_sub(/one.+/), test_sub('one'), test_sub(/one_.*/), test_sub('two'))
142
+ Application.new('myapp').subscribe(subs)
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
- 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"]])
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