la_gear 1.4.1 → 1.5.0

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: cf9273db3398beff1abd6c6c08ead4b5920ee23f
4
- data.tar.gz: 0dd534bf15e71aa64c3ddc811dde0957c1114ff6
3
+ metadata.gz: 50b9345a07b49e193edee1f97b92d57b4dab671a
4
+ data.tar.gz: 6dbed23ce229d49fc11e87779cb7a6b097e2fbf4
5
5
  SHA512:
6
- metadata.gz: 8cb73e5c7bc0325f91134bf232c2db3cc20735724d65f554dc1ed8300b0c592f14ea49d352b2b262a4f0057fd78850ee13ab0c5d50ef8e83e62ca5254423769c
7
- data.tar.gz: e71c3a811c35cedf26468f76f825ce9005c1dce3865974506283eed1eabbd240bc1566ec25137a773b1f423f38d4e51e8bdbe2213cdc540a9fb8eefb133f99ab
6
+ metadata.gz: 676d8f0232871ccd0b47c5f31e49c5572b66b7783887c96400299cbabf5f9c705eb5cec848149f48be94b9a2c95bade0066742c2acbbca76b2d2cfbcc2142079
7
+ data.tar.gz: 700b18d1fc8901f940273f7af277c8dbaf1294bd613004f65c985a331250c38f7528380b1d8b52a43c97b199682d7b1f78cde1b1ffab510ae8de1f026d7d7788
data/README.md CHANGED
@@ -35,7 +35,7 @@ Sneakers.configure app_name: 'pogs_are_awesome'
35
35
 
36
36
  class BoKnows
37
37
  include LaGear::Worker
38
-
38
+
39
39
  def perform(baseball, football)
40
40
  # process message ...
41
41
  end
@@ -60,6 +60,12 @@ class PowerRanger
60
60
  end
61
61
  ```
62
62
 
63
+ Or subscribe to multiple routing keys:
64
+
65
+ ```ruby
66
+ subscribes_to ['bo_knows', 'pump_it_up']
67
+ ```
68
+
63
69
  Also, notice in the example above that we don't define a `work` method for `Sneakers::Worker`. That's because `LaGear::Worker` defines it for you. All the method does is deserialize your RabbitMQ message (defaults to JSON) and pass each of the properties as a parameters to Sidekiq's `perform_async` method to process the message. Put your message processing code in a `perform` method instead. That's the method that Sidekiq invokes when it actually processes the message that `LaGear::Worker#work` sent to it.
64
70
 
65
71
  You can also use the conventions to create versioned workers to more easily handle backwards compatibility when message parameters change. This module/class:
@@ -79,7 +85,7 @@ would create the routing key `bo_knows.v1` and these queue names:
79
85
  - `pogs_are_awesome.bo_knows.v1`
80
86
  - `pogs_are_awesome.bo_knows.v1.retry`
81
87
 
82
- One caveat with `subscribes_to` and versioned workers is that the routing key must be manually incremented when a handler's version increments. If a worker `subscribes_to 'bo_knows.v1'`, and the `bo_knows.v1` message type increments to `bo_knows.v2`, you should create a new version of the worker that subscribes to `bo_knows.v2`.
88
+ One caveat with `subscribes_to` and versioned workers is that the routing key must be manually incremented when a handler's version increments. If a worker `subscribes_to 'bo_knows.v1'`, and the `bo_knows.v1` message type increments to `bo_knows.v2`, you should create a new version of the worker that subscribes to `bo_knows.v2`.
83
89
 
84
90
  ### The Bus
85
91
 
@@ -25,6 +25,15 @@ class TestWorker2
25
25
  def perform(_); end
26
26
  end
27
27
 
28
+ # multiple keys
29
+ class TestWorker3
30
+ include LaGear::Worker
31
+
32
+ subscribes_to [:test_worker, :test_worker3]
33
+
34
+ def perform(_); end
35
+ end
36
+
28
37
  Sneakers.logger.level = Logger::INFO
29
38
  bunny = Bunny.new
30
39
  bunny.start
@@ -37,17 +46,23 @@ queue2 = channel.queue(
37
46
  TestWorker2.default_queue_name,
38
47
  TestWorker2.default_queue_opts.merge(durable: true, arguments: TestWorker2.default_queue_args),
39
48
  )
49
+ queue3 = channel.queue(
50
+ TestWorker3.default_queue_name,
51
+ TestWorker3.default_queue_opts.merge(durable: true, arguments: TestWorker3.default_queue_args),
52
+ )
40
53
  queue.purge
41
- r = Sneakers::Runner.new([TestWorker, TestWorker2])
54
+ r = Sneakers::Runner.new([TestWorker, TestWorker2, TestWorker3])
42
55
  pid = fork do
43
56
  r.run
44
57
  end
45
58
  Process.detach(pid)
46
59
  LaGear::Publisher.new.publish(TestWorker.routing_key, ouch: 1)
60
+ LaGear::Publisher.new.publish(:test_worker3, ouch: 1)
47
61
  sleep 3
48
62
  puts 'killing...'
49
63
  Process.kill('TERM', pid)
50
64
  sleep 3
51
65
  puts "test_worker message count #{queue.message_count}"
52
66
  puts "test_worker2 message count #{queue2.message_count}"
67
+ puts "test_worker3 message count #{queue3.message_count}"
53
68
  exit 1 if queue.message_count > 0
@@ -1,3 +1,3 @@
1
1
  module LaGear
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -36,7 +36,7 @@ module LaGear
36
36
 
37
37
  def default_queue_opts
38
38
  {
39
- routing_key: [routing_key, retry_routing_key],
39
+ routing_key: [*routing_key, retry_routing_key],
40
40
  queue_options: {
41
41
  arguments: default_queue_args
42
42
  }.merge(::Sneakers::CONFIG.fetch(:global_queue_options, {})),
@@ -59,7 +59,7 @@ module LaGear
59
59
  end
60
60
 
61
61
  def subscribes_to(routing_key)
62
- @routing_key = routing_key.to_s
62
+ @routing_key = routing_key
63
63
  @default_queue_name = "#{app_name}.#{name.underscore.tr('/', '.')}"
64
64
  from_queue(default_queue_name, default_queue_opts) unless Worker.sidekiq_proc?
65
65
  end
data/test/test_worker.rb CHANGED
@@ -28,6 +28,12 @@ module SlapBraceletSender
28
28
  end
29
29
  end
30
30
 
31
+ class DoubleDutch
32
+ include LaGear::Worker
33
+
34
+ subscribes_to [PumpItUp.routing_key, NotPogs::V2.routing_key]
35
+ end
36
+
31
37
  class TestWorker < LaGear::Test
32
38
  describe 'when a worker is defined and there is a custom Sneakers app_name' do
33
39
  before do
@@ -194,5 +200,27 @@ class TestWorker < LaGear::Test
194
200
  )
195
201
  end
196
202
  end
203
+
204
+ describe 'when the worker subscribes to multiple keys' do
205
+ before do
206
+ @expected_queue_routing_key = ['pump_it_up', 'not_pogs.v2']
207
+ end
208
+
209
+ it 'must have pump_it_up and not_pogs.v2 as the routing keys' do
210
+ DoubleDutch.routing_key.must_equal @expected_queue_routing_key
211
+ end
212
+
213
+ it 'must have default queue options hash' do
214
+ DoubleDutch.default_queue_opts.must_equal(
215
+ routing_key: [PumpItUp.routing_key, NotPogs::V2.routing_key, DoubleDutch.retry_routing_key],
216
+ queue_options: {
217
+ arguments: DoubleDutch.default_queue_args
218
+ },
219
+ handler_opts: {
220
+ routing_key: DoubleDutch.retry_routing_key
221
+ }
222
+ )
223
+ end
224
+ end
197
225
  end
198
226
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: la_gear
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Chaney
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-06 00:00:00.000000000 Z
13
+ date: 2016-08-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json