pwwka 0.3.2 → 0.4.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: 0f8608f70d08fe1795cf8f7cf728d42edaf6ee5c
4
- data.tar.gz: 0a5510a4a7a059918659c859266c53c7dd4ceaf6
3
+ metadata.gz: b8270662062bb3b3031eb3cb2ddbe60975ce4946
4
+ data.tar.gz: e812c104a3f428ed34a85bedf7ca6c232e3a0336
5
5
  SHA512:
6
- metadata.gz: 273f205ae214815318c5436084c0aec578728842265df709b5774a95cfc60acb53bd2207f5306f11f591723d0d20bb07d3c43d8a184b8a28ad77cb3a87239b3a
7
- data.tar.gz: 3f2344a9ab055aed811ed4ce08fd1a14150372ce01422c9c05a4940e5082e482d615009fd1ec98552ac6dcd7e2c9248cc681dee43a1e8f01c7f2e2547ca427d0
6
+ metadata.gz: 8e5f383962104ef7d46796c7e21e83297e167e49768d83dbf59b289a5e147499f817f15e56e9b3c7266ada89d48b129ea64149d8bc42957959e83a7603250f6d
7
+ data.tar.gz: 991980da0be3f35934abb2edbda4d07f567440671273577b58d9d24ac56841b434180c98c6921bd3f0dca27be5368be11cbc979777abac69ce6b96ac6238896e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pwwka (0.3.2)
4
+ pwwka (0.4.0)
5
5
  activemodel
6
6
  activesupport
7
7
  bunny
@@ -10,10 +10,10 @@ PATH
10
10
  GEM
11
11
  remote: https://www.rubygems.org/
12
12
  specs:
13
- activemodel (4.1.4)
14
- activesupport (= 4.1.4)
13
+ activemodel (4.1.7)
14
+ activesupport (= 4.1.7)
15
15
  builder (~> 3.1)
16
- activesupport (4.1.4)
16
+ activesupport (4.1.7)
17
17
  i18n (~> 0.6, >= 0.6.9)
18
18
  json (~> 1.7, >= 1.7.7)
19
19
  minitest (~> 5.1)
@@ -21,29 +21,49 @@ GEM
21
21
  tzinfo (~> 1.1)
22
22
  amq-protocol (1.9.2)
23
23
  builder (3.2.2)
24
- bunny (1.4.0)
24
+ bunny (1.6.1)
25
25
  amq-protocol (>= 1.9.2)
26
26
  diff-lcs (1.2.5)
27
27
  i18n (0.6.11)
28
28
  json (1.8.1)
29
- minitest (5.4.0)
29
+ minitest (5.4.2)
30
30
  mono_logger (1.1.0)
31
+ multi_json (1.10.1)
32
+ rack (1.6.0)
33
+ rack-protection (1.5.3)
34
+ rack
31
35
  rake (10.3.2)
32
- rspec (3.0.0)
33
- rspec-core (~> 3.0.0)
34
- rspec-expectations (~> 3.0.0)
35
- rspec-mocks (~> 3.0.0)
36
- rspec-core (3.0.4)
37
- rspec-support (~> 3.0.0)
38
- rspec-expectations (3.0.4)
36
+ redis (3.2.0)
37
+ redis-namespace (1.5.1)
38
+ redis (~> 3.0, >= 3.0.4)
39
+ resque (1.25.2)
40
+ mono_logger (~> 1.0)
41
+ multi_json (~> 1.0)
42
+ redis-namespace (~> 1.3)
43
+ sinatra (>= 0.9.2)
44
+ vegas (~> 0.1.2)
45
+ rspec (3.1.0)
46
+ rspec-core (~> 3.1.0)
47
+ rspec-expectations (~> 3.1.0)
48
+ rspec-mocks (~> 3.1.0)
49
+ rspec-core (3.1.7)
50
+ rspec-support (~> 3.1.0)
51
+ rspec-expectations (3.1.2)
39
52
  diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.0.0)
41
- rspec-mocks (3.0.4)
42
- rspec-support (~> 3.0.0)
43
- rspec-support (3.0.4)
53
+ rspec-support (~> 3.1.0)
54
+ rspec-mocks (3.1.3)
55
+ rspec-support (~> 3.1.0)
56
+ rspec-support (3.1.2)
57
+ sinatra (1.4.5)
58
+ rack (~> 1.4)
59
+ rack-protection (~> 1.4)
60
+ tilt (~> 1.3, >= 1.3.4)
44
61
  thread_safe (0.3.4)
62
+ tilt (1.4.1)
45
63
  tzinfo (1.2.2)
46
64
  thread_safe (~> 0.1)
65
+ vegas (0.1.11)
66
+ rack (>= 1.0.0)
47
67
 
48
68
  PLATFORMS
49
69
  ruby
@@ -51,4 +71,5 @@ PLATFORMS
51
71
  DEPENDENCIES
52
72
  pwwka!
53
73
  rake
74
+ resque
54
75
  rspec
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Pronounced "Poo-ka" |ˈpo͞okə|
5
5
 
6
- ![Pwwka Bunny Bus](http://res.cloudinary.com/stitch-fix/image/upload/c_scale,w_317/v1408570794/bunny-bus_ba72ou.png)
6
+ ![Pwwka Legit](http://res.cloudinary.com/stitch-fix/image/upload/c_scale,h_300/v1413580920/pwwka_yuw7hl.png)
7
7
 
8
8
  ---
9
9
 
@@ -21,11 +21,11 @@ The basic principle of the Pwwka Message Bus is this:
21
21
 
22
22
  As an example:
23
23
 
24
- * public_app sends a message that a new client has signed up
25
- * admin_app receives that message and updates its client index
26
- * email_app receives that message and sends a welcome email to the client
24
+ * public-app sends a message that a new client has signed up
25
+ * admin-app receives that message and updates its client index
26
+ * email-app receives that message and sends a welcome email to the client
27
27
 
28
- ### Persistence
28
+ ## Persistence
29
29
 
30
30
  All transmitters and receivers share the same exchange. This means that all receivers can read all messages that any transmitter sends. To ensure that all messages are received by eveyone who wants them the Pwwka message bus is configured as follows:
31
31
 
@@ -115,7 +115,7 @@ Pwwka::Transmitter.send_message!(payload, routing_key, delayed: true, delay_by:
115
115
 
116
116
  `delay_by` is an integer of milliseconds to delay the message. The default (if no value is set) is 5000 (5 seconds).
117
117
 
118
- These extra arguments work for all message sending methods - the safe ones, the handling, and the message_queuer methods (see below).
118
+ These extra arguments work for all message sending methods - the safe ones, the handling, and the `message_queuer` methods (see below).
119
119
 
120
120
  ### Message Queuer
121
121
  You can queue up messages and send them in a batch. This is most useful when multiple messages need to sent from within a transaction block.
@@ -158,8 +158,8 @@ require 'pwwka/tasks'
158
158
 
159
159
  It depends on your `routing_key`. If you set your routing key to `#.#` (the default) it will receive all the messages. The `#` is a wildcard so if you set it to `client.#` it will receive any message with `client.` at the beginning. The exchange registers the queue's name and routing key so it knows what messages the queue is supposed to receive. A named queue will receive each message it expects to get once and only once.
160
160
 
161
- The available wildcards are as follows
162
- * `*` (star) can substitute for exactly one word.
161
+ The available wildcards are as follows (and are not intuitive):
162
+ * `*` (star) can substitute for **exactly one word**.
163
163
  * `#` (hash) can substitute for zero or more words.
164
164
 
165
165
  __A note on re-queuing:__ At the moment messages that raise an error on receipt are marked 'not acknowledged, don't resend', and the failure message is logged. All unacknowledged messages will be resent when the worker is restarted. The next iteration of this gem will allow for a specified number of resends without requiring a restart.
@@ -198,6 +198,51 @@ class ClientIndexMessageHandler
198
198
  end
199
199
  ```
200
200
 
201
+ #### Handling Messages with Resque
202
+
203
+ If you use [Resque][resque], and you wish to handle messages in a resque job, you can use `Pwwka::QueueResqueJobHandler`, which is an adapter between the
204
+ standard `handle!` method provided by pwwka and your Resque job.
205
+
206
+ 1. First, modify your `Gemfile` or otherwise arrange to include `pwwka/queue_resque_job_handler`:
207
+
208
+ ```ruby
209
+ gem 'pwwka', require: [ 'pwwka', 'pwwka/queue_resque_job_handler' ]
210
+ ```
211
+
212
+ or, in `config/initializers/pwwka.rb`:
213
+
214
+ ```ruby
215
+ require 'pwwka/queue_resque_job_handler'
216
+ ```
217
+
218
+ 2. Now, configure your handler. For a `Procfile` setup:
219
+
220
+ ```
221
+ my_handler: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyResqueJob QUEUE_NAME=my_queue ROUTING_KEY="my.key.completed"
222
+ ```
223
+
224
+ Note the use of the environment variable `JOB_KLASS`. This tells `QueueResqueJobHandler` which class to queue.
225
+ 3. Now, write your job.
226
+
227
+ ```ruby
228
+ class MyResqueJob
229
+ @queue = :my_resque_queue
230
+
231
+ def self.process(args) # i.e. payload
232
+ user = User.find(args.fetch("user_id")) # or whatever
233
+ user.frobnosticate!
234
+ end
235
+ end
236
+ ```
237
+
238
+ Note that you must provide `@queue` in your job. `QueueResqueJobHandler` doesn't support setting a custom queue and enqueue-time (PRs welcome :).
239
+ Note further that your job class is not given the routing key, so you'll have to set `ROUTING_KEY` appropriately for whatever it is you're trying to
240
+ do.
241
+ 3. Profit!
242
+
243
+ [resque]: https://github.com/resque/resque/tree/1-x-stable
244
+
245
+
201
246
  ## Monitoring
202
247
 
203
248
  RabbitMQ has a good API that should make it easy to set up some simple monitoring. In the meantime there is logging and manual monitoring.
@@ -0,0 +1,19 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'resque'
3
+
4
+ module Pwwka
5
+ # A handler that simply queues the payload into a Resque job. This is useful
6
+ # if the code that should respond to a message needs to be managed by Resque, e.g.
7
+ # for the purposes of retry or better failure management.
8
+ #
9
+ # You should be able to use this directly from your handler configuration, e.g. for a Heroku-style `Procfile`:
10
+ #
11
+ # my_handler: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyResqueJob QUEUE_NAME=my_queue ROUTING_KEY="my.key.completed"
12
+ #
13
+ # Note that this will not check the routing key, so you should be sure to specify the most precise ROUTING_KEY you can for handling the message.
14
+ class QueueResqueJobHandler
15
+ def self.handle!(delivery_info,properties,payload)
16
+ Resque.enqueue(ENV["JOB_KLASS"].constantize, payload)
17
+ end
18
+ end
19
+ end
data/lib/pwwka/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pwwka
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
data/pwwka.gemspec CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency("mono_logger")
25
25
  s.add_development_dependency("rake")
26
26
  s.add_development_dependency("rspec")
27
+ s.add_development_dependency("resque")
27
28
  end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+ require 'pwwka/queue_resque_job_handler'
3
+
4
+ class MyTestJob
5
+ end
6
+
7
+ describe Pwwka::QueueResqueJobHandler do
8
+
9
+ describe "::handle!" do
10
+ let(:job_class) { MyTestJob }
11
+ let(:delivery_info) { double("delivery info") }
12
+ let(:properties) { double("properties") }
13
+ let(:payload) {
14
+ {
15
+ "this" => "is",
16
+ "some" => true,
17
+ "payload" => 99,
18
+ }
19
+ }
20
+
21
+ before do
22
+ allow(Resque).to receive(:enqueue)
23
+ ENV["JOB_KLASS"] = MyTestJob.name
24
+
25
+ described_class.handle!(delivery_info,properties,payload)
26
+ end
27
+
28
+ it "should queue a resque job using JOB_KLASS and payload" do
29
+ expect(Resque).to have_received(:enqueue).with(MyTestJob,payload)
30
+ end
31
+
32
+ after do
33
+ ENV.delete("JOB_KLASS")
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwwka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stitch Fix Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: resque
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: |-
98
112
  The purpose of this gem is to normalise the sending and
99
113
  receiving of messages between Rails apps using the shared RabbitMQ
@@ -121,6 +135,7 @@ files:
121
135
  - lib/pwwka/handling.rb
122
136
  - lib/pwwka/logging.rb
123
137
  - lib/pwwka/message_queuer.rb
138
+ - lib/pwwka/queue_resque_job_handler.rb
124
139
  - lib/pwwka/receiver.rb
125
140
  - lib/pwwka/tasks.rb
126
141
  - lib/pwwka/test_handler.rb
@@ -130,6 +145,7 @@ files:
130
145
  - spec/handling_spec.rb
131
146
  - spec/logging_spec.rb
132
147
  - spec/message_queuer_spec.rb
148
+ - spec/queue_resque_job_handler_spec.rb
133
149
  - spec/receiver_spec.rb
134
150
  - spec/spec_helper.rb
135
151
  - spec/transmitter_spec.rb
@@ -152,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
168
  version: '0'
153
169
  requirements: []
154
170
  rubyforge_project:
155
- rubygems_version: 2.2.0.rc.1
171
+ rubygems_version: 2.4.2
156
172
  signing_key:
157
173
  specification_version: 4
158
174
  summary: Send and receive messages via RabbitMQ
@@ -160,6 +176,7 @@ test_files:
160
176
  - spec/handling_spec.rb
161
177
  - spec/logging_spec.rb
162
178
  - spec/message_queuer_spec.rb
179
+ - spec/queue_resque_job_handler_spec.rb
163
180
  - spec/receiver_spec.rb
164
181
  - spec/spec_helper.rb
165
182
  - spec/transmitter_spec.rb