la_gear 1.3.0 → 1.3.1

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: cf848e73d2235da6d435ad58dca4a1dc145c260d
4
- data.tar.gz: 0e6c492bd0154d0315a7475e03dce357991601fc
3
+ metadata.gz: 4ca8da71c32e27e8aabc8d13e7b00c12c5cc6107
4
+ data.tar.gz: d7eded901af06f3145c15f2395bc959d63f45082
5
5
  SHA512:
6
- metadata.gz: 6e2f6b5625e1b8c708029443d13da69e9734334713b66622de4f5cf64d8ce0984cd68dbea5823194a3eb99b593f86d7051ca82d15247646d2adedb8756db0732
7
- data.tar.gz: c45ddfbcb2dbcc5d64d9a7665576127466ea34b7deaa07b4672a537e3a2a1df741a41297b67a41fd428329eab6584871f8b27d669b410db2e1b4a79b6c1c24b7
6
+ metadata.gz: 90cbd481807e189e60dec7c78ff5cd707abdc93c63972077bd1c5efaab3c7659e0c5ab17759bb723cad38b1106826d654a6b64878054626fe3e3b82612034790
7
+ data.tar.gz: c49890fda1ecbaa23614da07584eb1f456539bb2b34fea737d0eccc5da0ed2a997d70e8aba3453f6660b6a8ac41b4e245d330aa9e2a03eaa96ff442bfedd10c3
data/README.md CHANGED
@@ -30,53 +30,74 @@ Or install it yourself as:
30
30
  ## Usage
31
31
 
32
32
  Instead of `include Sneakers::Worker` in your workers, use `include LaGear::Worker`. Then all of your queues and routing key bindings will automatically use an `Sneakers::Config[:app_name]` plus the class name of your worker as your queue name and the class name of your worker as the routing key. For example,
33
- ```
33
+ ```ruby
34
34
  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
- # ... message processing code ...
40
+ # process message ...
41
41
  end
42
42
  end
43
43
  ```
44
- would by default result in the following 2 queue names: `pogs_are_awesome.bo_knows` and `pogs_are_awesome.bo_knows.retry`. 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 `Sneakers::Worker#from_queue` method to override the convention-based defaults.
44
+ would by default result in the following 2 queue names:
45
45
 
46
- 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 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 actual processes the message that `LaGear::Worker#work` sent to it.
46
+ - `pogs_are_awesome.bo_knows`
47
+ - `pogs_are_awesome.bo_knows.retry`
47
48
 
48
- ### The Bus
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 `Sneakers::Worker#from_queue` method to override the convention-based defaults like so:
50
+
51
+ ```ruby
52
+ class PowerRanger
53
+ include LaGear::Worker
49
54
 
50
- 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).
55
+ def self.routing_key
56
+ 'bo_knows'
57
+ end
51
58
 
52
- `LaGear::Bus` also has support for BigWig's [bi-endpoint]((https://devcenter.heroku.com/articles/rabbitmq-bigwig#provisioning-the-add-on)) configuration where they use one RabbitMQ endpoint for receiving and one for transmitting. Configure Sneaker with an `amqp` and `amqp_publish` to get this working. Or you can just use the `LaGear::SneakersConfigurer.configure_bi_amqp_endpoints` convience method. Here's an example for a Heroku app:
53
- ```
54
- if ENV['RABBITMQ_BIGWIG_RX_URL'] && ENV['RABBITMQ_BIGWIG_TX_URL']
55
- LaGear::SneakersConfigurer.configure_bi_amqp_endpoints(
56
- ENV['RABBITMQ_BIGWIG_RX_URL'],
57
- ENV['RABBITMQ_BIGWIG_TX_URL']
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
64
+
65
+ def perform(red, yellow)
66
+ # process message...
67
+ end
59
68
  end
60
- # else Sneakers/Bunny just uses the default RabbitMQ endpoint (amqp://localhost:15672)
61
69
  ```
62
70
 
63
- The reason I call it a "bus" is because I want to end up adding bus-style semantic methods to it besides publish similar to the methods in NServiceBus's [`IBus`](https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/IBus.cs) (see also [`ISendOnlyBus`](https://github.com/Particular/NServiceBus/blob/develop/src/NServiceBus.Core/ISendOnlyBus.cs)).
71
+ 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
72
 
65
- ## Known Issues
73
+ You can also use the conventions to create versioned workers to more easily handle backwards compatibility when message parameters change. This module/class:
66
74
 
67
- * For workers in a Rails 3.2 app I have, I had to explicilty include `Sneakers::Worker` and `Sidekiq::Worker` before `LaGear::Worker` because of an issue with it complaing that the `include` method was private in the Rails environment (see [here](https://github.com/gabrieljoelc/la_gear/blob/master/lib/la_gear/worker.rb#L6) for the current workaround). Here's what your workers should look like if this is happening to you:
68
- ```
69
- class BoKnows
70
- include Sneakers::Worker unless LaGear::Worker.sidekiq_proc?
71
- include Sidekiq::Worker
72
- include LaGear::Worker
73
-
74
- def perform(baseball, football)
75
- # ... your worker code ...
75
+ ```ruby
76
+ module BoKnows
77
+ class V1
78
+ def perform
79
+ # process message...
80
+ end
76
81
  end
77
82
  end
78
83
  ```
79
84
 
85
+ would create the routing key `bo_knows.v1` and these queue names:
86
+
87
+ - `pogs_are_awesome.bo_knows.v1`
88
+ - `pogs_are_awesome.bo_knows.v1.retry`
89
+
90
+ ### The Bus
91
+
92
+ 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:
93
+
94
+ - `LaGear::Bus.publish('bo_knows', baseball: 'royals', football: 'cowboys')`
95
+ - `LaGear::Bus.publish('bo_knows', { baseball: 'royals', football: 'cowboys' }, version: 2)` - will publish to the exchange with the `bo_knows.v2` routing key
96
+ - `LaGear::Bus.publish_in(1.day, 'bo_knows', baseball: 'royals', football: 'cowboys')`
97
+ - `LaGear::Bus.publish_at(1.day.from_now, 'bo_knows', baseball: 'royals', football: 'cowboys')`
98
+ - `LaGear::Bus.publish_local('bo_knows_local', baseball: 'royals', football: 'cowboys')` - this is for local only (`include Sidekiq::Worker`) workers
99
+ - `LaGear::Bus.publish_local_in('bo_knows', { baseball: 'royals', football: 'cowboys' }, 1.day)`
100
+
80
101
  ## Contributing
81
102
 
82
103
  1. Fork it ( https://github.com/[my-github-username]/la_gear/fork )
data/la_gear.gemspec CHANGED
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'bunny', '~> 2.2.0'
22
22
  spec.add_dependency 'sneakers', '~> 2.3'
23
23
  spec.add_dependency 'activesupport', '~> 4.2'
24
- spec.add_dependency 'sidekiq', '~> 3.3'
24
+ spec.add_dependency 'sidekiq', '>= 3.3'
25
25
  spec.add_dependency 'connection_pool', '~> 2.1'
26
26
 
27
27
  spec.add_development_dependency 'rake', '~> 10.4'
28
28
  spec.add_development_dependency 'minitest', '~> 5.7.0'
29
29
  spec.add_development_dependency 'simplecov'
30
- spec.add_development_dependency 'rr'
30
+ spec.add_development_dependency 'mocha'
31
31
  spec.add_development_dependency 'pry'
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module LaGear
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
data/test/helper.rb CHANGED
@@ -12,6 +12,7 @@ rescue LoadError
12
12
  end
13
13
  require 'minitest/autorun'
14
14
  require 'minitest/pride'
15
+ require 'mocha/mini_test'
15
16
  require 'sidekiq'
16
17
  require 'sneakers'
17
18
 
@@ -79,8 +79,6 @@ class TestPublisher < LaGear::Test
79
79
  end
80
80
 
81
81
  describe 'when serialize is overriden to be a no-op' do
82
- require 'rr'
83
-
84
82
  class PumpItUpPublisher < LaGear::Publisher
85
83
  def self.serialize(msg)
86
84
  msg
@@ -96,46 +94,46 @@ class TestPublisher < LaGear::Test
96
94
 
97
95
  it 'should publish a message to an exchange' do
98
96
  xchg = Object.new
99
- mock(xchg).publish('test msg', routing_key: 'downloads')
97
+ xchg.expects(:publish).with('test msg', routing_key: 'downloads')
100
98
 
101
99
  p = PumpItUpPublisher.new
102
100
  p.instance_variable_set(:@exchange, xchg)
103
101
 
104
- mock(p).ensure_connection! {}
102
+ p.stubs(:ensure_connection!)
105
103
  p.publish('test msg', to_queue: 'downloads')
106
104
  end
107
105
 
108
106
  it 'should publish with the persistence specified' do
109
107
  xchg = Object.new
110
- mock(xchg).publish('test msg', routing_key: 'downloads', persistence: true)
108
+ xchg.expects(:publish).with('test msg', routing_key: 'downloads', persistence: true)
111
109
 
112
110
  p = PumpItUpPublisher.new
113
111
  p.instance_variable_set(:@exchange, xchg)
114
112
 
115
- mock(p).ensure_connection! {}
113
+ p.stubs(:ensure_connection!)
116
114
  p.publish('test msg', to_queue: 'downloads', persistence: true)
117
115
  end
118
116
 
119
117
  it 'should publish with arbitrary metadata specified' do
120
118
  xchg = Object.new
121
- mock(xchg).publish('test msg', routing_key: 'downloads', expiration: 1, headers: { foo: 'bar' })
119
+ xchg.expects(:publish).with('test msg', routing_key: 'downloads', expiration: 1, headers: { foo: 'bar' })
122
120
 
123
121
  p = PumpItUpPublisher.new
124
122
  p.instance_variable_set(:@exchange, xchg)
125
123
 
126
- mock(p).ensure_connection! {}
124
+ p.stubs(:ensure_connection!)
127
125
  p.publish('test msg', to_queue: 'downloads', expiration: 1, headers: { foo: 'bar' })
128
126
  end
129
127
 
130
128
  it 'should not reconnect if already connected' do
131
129
  xchg = Object.new
132
- mock(xchg).publish('test msg', routing_key: 'downloads')
130
+ xchg.expects(:publish).with('test msg', routing_key: 'downloads')
133
131
 
134
132
  p = PumpItUpPublisher.new
135
133
  p.instance_variable_set(:@exchange, xchg)
136
134
 
137
- mock(p).connected? { true }
138
- mock(p).ensure_connection!.times(0)
135
+ p.stubs(:connected?).returns(true)
136
+ p.expects(:ensure_connection!).never
139
137
 
140
138
  p.publish('test msg', to_queue: 'downloads')
141
139
  end
@@ -151,15 +149,15 @@ class TestPublisher < LaGear::Test
151
149
  durable: false)
152
150
 
153
151
  channel = Object.new
154
- mock(channel).exchange('another_exchange', type: :topic, durable: false) do
155
- mock(Object.new).publish('test msg', routing_key: 'downloads')
152
+ channel.expects(:exchange).with('another_exchange', type: :topic, durable: false) do
153
+ Object.new.expects(:publish).with('test msg', routing_key: 'downloads')
156
154
  end
157
155
 
158
156
  bunny = Object.new
159
- mock(bunny).start
160
- mock(bunny).create_channel { channel }
157
+ bunny.expects(:start)
158
+ bunny.stubs(:create_channel).returns(channel)
161
159
 
162
- mock(Bunny).new('amqp://someuser:somepassword@somehost:5672', heartbeat: 1, vhost: '/', logger: logger) { bunny }
160
+ Bunny.expects(:new).with('amqp://someuser:somepassword@somehost:5672', heartbeat: 1, vhost: '/', logger: logger).returns bunny
163
161
 
164
162
  p = PumpItUpPublisher.new
165
163
 
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.3.0
4
+ version: 1.3.1
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: 2015-10-12 00:00:00.000000000 Z
13
+ date: 2016-01-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -72,14 +72,14 @@ dependencies:
72
72
  name: sidekiq
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - "~>"
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3.3'
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - "~>"
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '3.3'
85
85
  - !ruby/object:Gem::Dependency
@@ -139,7 +139,7 @@ dependencies:
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  - !ruby/object:Gem::Dependency
142
- name: rr
142
+ name: mocha
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
145
  - - ">="