la_gear 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +4 -10
- data/examples/test_worker.rb +17 -2
- data/lib/la_gear/version.rb +1 -1
- data/lib/la_gear/worker.rb +12 -2
- data/test/test_worker.rb +45 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 768160cb15b491dd985aef30be9cc2b29bf9ddc2
|
4
|
+
data.tar.gz: 49f88664b7440dc21470f9778ed616fba089bf2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b461a62b63c2d45cdaa13db78ec0cec265270594a6836eeba5388bed709820b631391885395124d89fa0deb33aea9c380479f5434b7e3775faef16ee5c99f938
|
7
|
+
data.tar.gz: df2ff3bab0755e9a06c7a2c8dcb38f991cbffe7b632a7de7660dc3823fd8ee5b26f892f8e89cdc036000c3509f965b7a6ee3d61261056533c7b67b3310c15ed3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -46,21 +46,13 @@ would by default result in the following 2 queue names:
|
|
46
46
|
- `pogs_are_awesome.bo_knows`
|
47
47
|
- `pogs_are_awesome.bo_knows.retry`
|
48
48
|
|
49
|
-
The default routing key would be: `bo_knows`. This allows for multiple consumer queue bindings for a direct exchange (see the Multiple Bindings section of https://www.rabbitmq.com/tutorials/tutorial-four-ruby.html). The `.retry` is for if you are using [dead letter exchanges](https://www.rabbitmq.com/dlx.html) and [message expirations](https://www.rabbitmq.com/ttl.html) to perform retries (which you should). Just call the `
|
49
|
+
The default routing key would be: `bo_knows`. This allows for multiple consumer queue bindings for a direct exchange (see the Multiple Bindings section of https://www.rabbitmq.com/tutorials/tutorial-four-ruby.html). The `.retry` is for if you are using [dead letter exchanges](https://www.rabbitmq.com/dlx.html) and [message expirations](https://www.rabbitmq.com/ttl.html) to perform retries (which you should). Just call the `subscribes_to` method to override the convention-based defaults like so:
|
50
50
|
|
51
51
|
```ruby
|
52
52
|
class PowerRanger
|
53
53
|
include LaGear::Worker
|
54
54
|
|
55
|
-
|
56
|
-
'bo_knows'
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.default_queue_name
|
60
|
-
"#{Sneakers::CONFIG.fetch(:app_name).underscore}.#{name.underscore}"
|
61
|
-
end
|
62
|
-
|
63
|
-
from_queue default_queue_name, default_queue_opts
|
55
|
+
subscribes_to 'bo_knows'
|
64
56
|
|
65
57
|
def perform(red, yellow)
|
66
58
|
# process message...
|
@@ -87,6 +79,8 @@ would create the routing key `bo_knows.v1` and these queue names:
|
|
87
79
|
- `pogs_are_awesome.bo_knows.v1`
|
88
80
|
- `pogs_are_awesome.bo_knows.v1.retry`
|
89
81
|
|
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`.
|
83
|
+
|
90
84
|
### The Bus
|
91
85
|
|
92
86
|
There is also a `LaGear::Bus` class which is an alternative to the `Sneakers::Publisher`. It adds an `opts` parameter to the `publish` method, allowing you to pass the options you would pass to the `bunny` exchange publish [method](http://reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method) (see http://reference.rubybunny.info/Bunny/Exchange.html#publish-instance_method for the list of options). It also allows you use a common way to publish messages:
|
data/examples/test_worker.rb
CHANGED
@@ -9,12 +9,22 @@ Sneakers.configure(
|
|
9
9
|
handler: LaGear::Sneakers::Handlers::ExponentialBackoff
|
10
10
|
)
|
11
11
|
|
12
|
+
# old way
|
12
13
|
class TestWorker
|
13
14
|
include LaGear::Worker
|
14
15
|
|
15
16
|
def perform(_); end
|
16
17
|
end
|
17
18
|
|
19
|
+
# new way
|
20
|
+
class TestWorker2
|
21
|
+
include LaGear::Worker
|
22
|
+
|
23
|
+
subscribes_to :test_worker
|
24
|
+
|
25
|
+
def perform(_); end
|
26
|
+
end
|
27
|
+
|
18
28
|
Sneakers.logger.level = Logger::INFO
|
19
29
|
bunny = Bunny.new
|
20
30
|
bunny.start
|
@@ -23,8 +33,12 @@ queue = channel.queue(
|
|
23
33
|
TestWorker.default_queue_name,
|
24
34
|
TestWorker.default_queue_opts.merge(durable: true, arguments: TestWorker.default_queue_args),
|
25
35
|
)
|
36
|
+
queue2 = channel.queue(
|
37
|
+
TestWorker2.default_queue_name,
|
38
|
+
TestWorker2.default_queue_opts.merge(durable: true, arguments: TestWorker2.default_queue_args),
|
39
|
+
)
|
26
40
|
queue.purge
|
27
|
-
r = Sneakers::Runner.new([TestWorker])
|
41
|
+
r = Sneakers::Runner.new([TestWorker, TestWorker2])
|
28
42
|
pid = fork do
|
29
43
|
r.run
|
30
44
|
end
|
@@ -34,5 +48,6 @@ sleep 3
|
|
34
48
|
puts 'killing...'
|
35
49
|
Process.kill('TERM', pid)
|
36
50
|
sleep 3
|
37
|
-
puts "message count #{queue.message_count}"
|
51
|
+
puts "test_worker message count #{queue.message_count}"
|
52
|
+
puts "test_worker2 message count #{queue2.message_count}"
|
38
53
|
exit 1 if queue.message_count > 0
|
data/lib/la_gear/version.rb
CHANGED
data/lib/la_gear/worker.rb
CHANGED
@@ -26,8 +26,12 @@ module LaGear
|
|
26
26
|
end
|
27
27
|
|
28
28
|
module SneakersClassMethods
|
29
|
+
def app_name
|
30
|
+
::Sneakers::CONFIG.fetch(:app_name, 'sneakers').underscore
|
31
|
+
end
|
32
|
+
|
29
33
|
def default_queue_name
|
30
|
-
"#{
|
34
|
+
@default_queue_name ||= "#{app_name}.#{routing_key}"
|
31
35
|
end
|
32
36
|
|
33
37
|
def default_queue_opts
|
@@ -43,7 +47,7 @@ module LaGear
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def routing_key
|
46
|
-
name.underscore.
|
50
|
+
@routing_key ||= name.underscore.tr('/', '.')
|
47
51
|
end
|
48
52
|
|
49
53
|
def retry_routing_key
|
@@ -53,6 +57,12 @@ module LaGear
|
|
53
57
|
def default_queue_args
|
54
58
|
{ 'x-dead-letter-exchange' => "#{::Sneakers::CONFIG.fetch(:exchange, 'sneakers').underscore}.retry" }
|
55
59
|
end
|
60
|
+
|
61
|
+
def subscribes_to(routing_key)
|
62
|
+
@routing_key = routing_key.to_s
|
63
|
+
@default_queue_name = "#{app_name}.#{name.underscore.tr('/', '.')}"
|
64
|
+
from_queue(default_queue_name, default_queue_opts) unless Worker.sidekiq_proc?
|
65
|
+
end
|
56
66
|
end
|
57
67
|
|
58
68
|
module NoOpSneakersClassMethods
|
data/test/test_worker.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require_relative 'helper'
|
2
2
|
|
3
|
+
Sneakers::CONFIG[:app_name] = 'bo_knows'
|
4
|
+
Sneakers::CONFIG[:exchange] = 'football'
|
5
|
+
|
3
6
|
class PumpItUp
|
4
7
|
include LaGear::Worker
|
5
8
|
end
|
@@ -17,6 +20,14 @@ module GoGo
|
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
23
|
+
module SlapBraceletSender
|
24
|
+
class V1
|
25
|
+
include LaGear::Worker
|
26
|
+
|
27
|
+
subscribes_to NotPogs::V2.routing_key
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
20
31
|
class TestWorker < LaGear::Test
|
21
32
|
describe 'when a worker is defined and there is a custom Sneakers app_name' do
|
22
33
|
before do
|
@@ -91,10 +102,6 @@ class TestWorker < LaGear::Test
|
|
91
102
|
NotPogs::V2.routing_key.must_equal @expected_queue_routing_key
|
92
103
|
end
|
93
104
|
|
94
|
-
it 'must have pump_it_up as the routing_key' do
|
95
|
-
NotPogs::V2.routing_key.must_equal @expected_queue_routing_key
|
96
|
-
end
|
97
|
-
|
98
105
|
it 'must have bo_knows.pump_it_up as the default_queue_name' do
|
99
106
|
NotPogs::V2.default_queue_name.must_equal "#{Sneakers::CONFIG[:app_name]}.#{@expected_queue_routing_key}"
|
100
107
|
end
|
@@ -129,10 +136,6 @@ class TestWorker < LaGear::Test
|
|
129
136
|
GoGo::PowerRangers::V2.routing_key.must_equal @expected_queue_routing_key
|
130
137
|
end
|
131
138
|
|
132
|
-
it 'must have pump_it_up as the routing_key' do
|
133
|
-
GoGo::PowerRangers::V2.routing_key.must_equal @expected_queue_routing_key
|
134
|
-
end
|
135
|
-
|
136
139
|
it 'must have bo_knows.pump_it_up as the default_queue_name' do
|
137
140
|
GoGo::PowerRangers::V2.default_queue_name.must_equal "#{Sneakers::CONFIG[:app_name]}.#{@expected_queue_routing_key}"
|
138
141
|
end
|
@@ -157,5 +160,39 @@ class TestWorker < LaGear::Test
|
|
157
160
|
)
|
158
161
|
end
|
159
162
|
end
|
163
|
+
|
164
|
+
describe 'when the worker is namespaced once and invokes subscribes_to' do
|
165
|
+
before do
|
166
|
+
@expected_queue_routing_key = 'not_pogs.v2'
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'must have not_pogs.v2 as the routing_key' do
|
170
|
+
SlapBraceletSender::V1.routing_key.must_equal @expected_queue_routing_key
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'must have bo_knows.slap_bracelet_sender.v1 as the default_queue_name' do
|
174
|
+
SlapBraceletSender::V1.default_queue_name.must_equal "#{Sneakers::CONFIG[:app_name]}.#{SlapBraceletSender::V1.name.underscore.tr('/', '.')}"
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'must have bo_knows.slap_bracelet_sender.v1.retry as the retry_routing_key' do
|
178
|
+
SlapBraceletSender::V1.retry_routing_key.must_equal "#{Sneakers::CONFIG[:app_name]}.#{SlapBraceletSender::V1.name.underscore.tr('/', '.')}.retry"
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'must have default queue has with x-dead-letter-exchange of football.retry' do
|
182
|
+
SlapBraceletSender::V1.default_queue_args.must_equal 'x-dead-letter-exchange' => "#{Sneakers::CONFIG[:exchange]}.retry"
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'must have default queue options hash' do
|
186
|
+
SlapBraceletSender::V1.default_queue_opts.must_equal(
|
187
|
+
routing_key: [SlapBraceletSender::V1.routing_key, SlapBraceletSender::V1.retry_routing_key],
|
188
|
+
queue_options: {
|
189
|
+
arguments: SlapBraceletSender::V1.default_queue_args
|
190
|
+
},
|
191
|
+
handler_opts: {
|
192
|
+
routing_key: SlapBraceletSender::V1.retry_routing_key
|
193
|
+
}
|
194
|
+
)
|
195
|
+
end
|
196
|
+
end
|
160
197
|
end
|
161
198
|
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
|
+
version: 1.4.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-
|
13
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|