pwwka 0.11.0 → 0.12.0.RC1

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: 68a8e54adf4b1cb502093fcdc621154f449a0664
4
- data.tar.gz: b3cf3d62c2d3dc6c914c83c48202fb1642058c67
3
+ metadata.gz: 74547cd8f8b4313cb47333486277bc22aad36e76
4
+ data.tar.gz: e14256ef72ea644b30f1c7af7305a5047dfdd6f3
5
5
  SHA512:
6
- metadata.gz: 7b205ad3d18ebab8a85fff6a851e8258f3e001ee69fa74212a168808aa197e46b625c7335ad6e39d064297973cd85c5852cb299af23ebd57aa604aa9bdeceb3e
7
- data.tar.gz: 79397d68abe1839b28d561a74240b39f735b9c4322e296dad22d25aff7d476661296f3a4e0f7149f5dc5b00047f2d3344d23e035e12f02db05b9d69104d76ac9
6
+ metadata.gz: 5d000df76add8d1449072d15e75c0f3ec05aab8a5a4e07b5251fa9d041e4ca8a784d57c94fa77c3eebef2283d5eb1e69f0bed9d5d9c5525ec5d728dd91a4908a
7
+ data.tar.gz: 164001e94240f3d154a605a808fafe196686a5006340cae84d9a8b03dd0c6deb29450b542dc5d0c937d1b1477006fb3475b50d0d62c5ade28650e34975234081
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pwwka (0.11.0)
4
+ pwwka (0.12.0.RC1)
5
5
  activemodel
6
6
  activesupport
7
7
  bunny
@@ -10,9 +10,9 @@ PATH
10
10
  GEM
11
11
  remote: https://www.rubygems.org/
12
12
  specs:
13
- activemodel (5.1.1)
14
- activesupport (= 5.1.1)
15
- activesupport (5.1.1)
13
+ activemodel (5.1.3)
14
+ activesupport (= 5.1.3)
15
+ activesupport (5.1.3)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (~> 0.7)
18
18
  minitest (~> 5.1)
@@ -25,9 +25,9 @@ GEM
25
25
  docile (1.1.5)
26
26
  et-orbi (1.0.4)
27
27
  tzinfo
28
- i18n (0.8.4)
28
+ i18n (0.8.6)
29
29
  json (2.1.0)
30
- minitest (5.10.2)
30
+ minitest (5.10.3)
31
31
  mono_logger (1.1.0)
32
32
  multi_json (1.12.1)
33
33
  mustermann (1.0.0)
@@ -102,4 +102,4 @@ DEPENDENCIES
102
102
  simplecov
103
103
 
104
104
  BUNDLED WITH
105
- 1.14.6
105
+ 1.15.4
data/README.md CHANGED
@@ -301,7 +301,7 @@ If you use [Resque][resque], and you wish to handle messages in a resque job, yo
301
301
  2. Now, configure your handler. For a `Procfile` setup:
302
302
 
303
303
  ```
304
- my_handler: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyResqueJob QUEUE_NAME=my_queue ROUTING_KEY="my.key.completed"
304
+ my_handler: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyResqueJob PWWKA_QUEUE_EXTENDED_INFO=true QUEUE_NAME=my_queue ROUTING_KEY="my.key.completed"
305
305
  ```
306
306
 
307
307
  Note the use of the environment variable `JOB_KLASS`. This tells `QueueResqueJobHandler` which class to queue.
@@ -311,16 +311,18 @@ If you use [Resque][resque], and you wish to handle messages in a resque job, yo
311
311
  class MyResqueJob
312
312
  @queue = :my_resque_queue
313
313
 
314
- def self.process(args) # i.e. payload
315
- user = User.find(args.fetch("user_id")) # or whatever
314
+ def self.perform(payload, # the payload
315
+ routing_key, # routing key as a string
316
+ message_properties) # properties as a hash with _String_ keys
317
+ user = User.find(payload.fetch("user_id")) # or whatever
316
318
  user.frobnosticate!
317
319
  end
318
320
  end
319
321
  ```
320
322
 
321
- Note that you must provide `@queue` in your job. `QueueResqueJobHandler` doesn't support setting a custom queue and enqueue-time (PRs welcome :).
322
- 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
323
- do.
323
+ Note that you must provide `@queue` in your job. `QueueResqueJobHandler` doesn't support setting a custom queue at enqueue-time (PRs welcome :).
324
+
325
+ Note that if you were using this library before version 0.12.0, your job would only be given the payload. This is why `PWWKA_QUEUE_EXTENDED_INFO` must be set. Without it, your job only gets the payload to avoid breaking legacy consumers. You should always set this so you have access to the entire message.
324
326
  3. Profit!
325
327
 
326
328
  [resque]: https://github.com/resque/resque/tree/1-x-stable
@@ -4,16 +4,26 @@ require 'resque'
4
4
  module Pwwka
5
5
  # A handler that simply queues the payload into a Resque job. This is useful
6
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.
7
+ # for the purposes of retry or better failure management. You can ask for the routing key and properties
8
+ # by setting `PWWKA_QUEUE_EXTENDED_INFO` to `true` in your environment.
8
9
  #
9
10
  # You should be able to use this directly from your handler configuration, e.g. for a Heroku-style `Procfile`:
10
11
  #
11
12
  # my_handler: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyResqueJob QUEUE_NAME=my_queue ROUTING_KEY="my.key.completed"
13
+ # my_handler_that_wants_more_info: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyOthgerResqueJob PWWKA_QUEUE_EXTENDED_INFO=true QUEUE_NAME=my_queue ROUTING_KEY="my.key.#"
12
14
  #
13
15
  # 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
16
  class QueueResqueJobHandler
15
17
  def self.handle!(delivery_info,properties,payload)
16
- Resque.enqueue(ENV["JOB_KLASS"].constantize, payload)
18
+ args = [
19
+ ENV["JOB_KLASS"].constantize,
20
+ payload
21
+ ]
22
+ if ENV["PWWKA_QUEUE_EXTENDED_INFO"] == 'true'
23
+ args << delivery_info.routing_key
24
+ args << properties.to_hash
25
+ end
26
+ Resque.enqueue(*args)
17
27
  end
18
28
  end
19
29
  end
data/lib/pwwka/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pwwka
2
- VERSION = '0.11.0'
2
+ VERSION = '0.12.0.RC1'
3
3
  end
@@ -1,5 +1,7 @@
1
1
  require 'spec_helper.rb'
2
2
  require 'resqutils/spec/resque_helpers'
3
+ require 'resqutils/spec/resque_matchers'
4
+ require 'pwwka/queue_resque_job_handler'
3
5
 
4
6
  require_relative "support/integration_test_setup"
5
7
  require_relative "support/logging_receiver"
@@ -10,25 +12,30 @@ describe "sending and receiving messages", :integration do
10
12
  include Resqutils::Spec::ResqueHelpers
11
13
 
12
14
  before do
15
+ ENV["JOB_KLASS"] = MyTestJob.name
16
+ ENV["PWWKA_QUEUE_EXTENDED_INFO"] = "true"
13
17
  @testing_setup = IntegrationTestSetup.new
14
18
  [
15
- [AllReceiver , "all_receiver_pwwkatesting" , "#"] ,
16
- [FooReceiver , "foo_receiver_pwwkatesting" , "pwwka.testing.foo"] ,
17
- [OtherFooReceiver , "other_foo_receiver_pwwkatesting" , "pwwka.testing.foo"] ,
19
+
20
+ [AllReceiver , "all_receiver_pwwkatesting" , "#"] ,
21
+ [FooReceiver , "foo_receiver_pwwkatesting" , "pwwka.testing.foo"] ,
22
+ [OtherFooReceiver , "other_foo_receiver_pwwkatesting" , "pwwka.testing.foo"] ,
23
+ [Pwwka::QueueResqueJobHandler , "queue_resque_job_handler_pwwkatesting" , "#" ] ,
24
+
18
25
  ].each do |(klass, queue_name, routing_key)|
19
26
  @testing_setup.make_queue_and_setup_receiver(klass,queue_name,routing_key)
20
27
  end
21
- end
22
-
23
- before :each do
24
28
  AllReceiver.reset!
25
29
  FooReceiver.reset!
26
30
  OtherFooReceiver.reset!
27
31
  clear_queue(:delayed)
32
+ clear_queue(MyTestJob)
28
33
  end
29
34
 
30
35
  after do
31
36
  @testing_setup.kill_threads_and_clear_queues
37
+ ENV.delete("JOB_KLASS")
38
+ ENV.delete("PWWKA_QUEUE_EXTENDED_INFO")
32
39
  end
33
40
 
34
41
  context "routing" do
@@ -201,6 +208,32 @@ describe "sending and receiving messages", :integration do
201
208
  expect(OtherFooReceiver.messages_received.size).to eq(1)
202
209
  end
203
210
 
211
+ it "can receive a message on a handler that just queues background jobs" do
212
+ payload = { sample: "payload", has: { deeply: true, nested: 4 }}
213
+ Pwwka::Transmitter.send_message!(payload, "foo.bar")
214
+
215
+ allow_receivers_to_process_queues
216
+
217
+ job = Resque.pop(:test_queue)
218
+ aggregate_failures "job paylod" do
219
+ expect(job["class"]).to eq(MyTestJob.name)
220
+ expect(job["args"][0]).to eq({ "sample" => "payload", "has" => { "deeply" => true, "nested" => 4 }})
221
+ expect(job["args"][1]).to eq("foo.bar")
222
+
223
+ # Expect a few things from the metadata for sanity
224
+ expect(job["args"][2].keys).to include("content_type")
225
+ expect(job["args"][2].keys).to include("message_id")
226
+ expect(job["args"][2].keys).to include("timestamp")
227
+ end
228
+ end
229
+
230
+ class MyTestJob
231
+ @queue = "test_queue"
232
+
233
+ def self.perform(payload,routing_key,properties)
234
+ end
235
+ end
236
+
204
237
 
205
238
  class AllReceiver < LoggingReceiver
206
239
  end
data/spec/spec_helper.rb CHANGED
@@ -46,8 +46,7 @@ RSpec.configure do |config|
46
46
  if example.metadata[:integration]
47
47
  result = test_configuration.check_services
48
48
  unless result.up?
49
- puts "\n\n" + Rainbow(result.error).yellow.bright + "\n\n"
50
- exit 1
49
+ fail result.error
51
50
  end
52
51
  end
53
52
  example.run
@@ -8,8 +8,16 @@ describe Pwwka::QueueResqueJobHandler do
8
8
 
9
9
  describe "::handle!" do
10
10
  let(:job_class) { MyTestJob }
11
- let(:delivery_info) { double("delivery info") }
12
- let(:properties) { double("properties") }
11
+ let(:routing_key) { "foo.bar.blah" }
12
+ let(:delivery_info) { double("delivery info", routing_key: routing_key) }
13
+ let(:properties_hash) {
14
+ {
15
+ "app_id" => "myapp",
16
+ "timestamp" => "2015-12-12 13:22:99",
17
+ "message_id" => "66",
18
+ }
19
+ }
20
+ let(:properties) { Bunny::MessageProperties.new(properties_hash) }
13
21
  let(:payload) {
14
22
  {
15
23
  "this" => "is",
@@ -21,16 +29,34 @@ describe Pwwka::QueueResqueJobHandler do
21
29
  before do
22
30
  allow(Resque).to receive(:enqueue)
23
31
  ENV["JOB_KLASS"] = MyTestJob.name
32
+ end
33
+
34
+ context "when not asking for more information explicitly" do
35
+ it "should queue a resque job using JOB_KLASS and the payload" do
36
+ described_class.handle!(delivery_info,properties,payload)
37
+ expect(Resque).to have_received(:enqueue).with(MyTestJob,payload)
38
+ end
39
+ end
24
40
 
25
- described_class.handle!(delivery_info,properties,payload)
41
+ context "when asking to NOT receive more information explicitly" do
42
+ it "should queue a resque job using JOB_KLASS and the payload" do
43
+ ENV["PWWKA_QUEUE_EXTENDED_INFO"] = 'false'
44
+ described_class.handle!(delivery_info,properties,payload)
45
+ expect(Resque).to have_received(:enqueue).with(MyTestJob,payload)
46
+ end
26
47
  end
27
48
 
28
- it "should queue a resque job using JOB_KLASS and payload" do
29
- expect(Resque).to have_received(:enqueue).with(MyTestJob,payload)
49
+ context "when asking for more information via PWWKA_QUEUE_EXTENDED_INFO" do
50
+ it "should queue a resque job using JOB_KLASS, payload, routing key, and properties as a hash" do
51
+ ENV["PWWKA_QUEUE_EXTENDED_INFO"] = 'true'
52
+ described_class.handle!(delivery_info,properties,payload)
53
+ expect(Resque).to have_received(:enqueue).with(MyTestJob,payload,routing_key,properties_hash)
54
+ end
30
55
  end
31
56
 
32
57
  after do
33
58
  ENV.delete("JOB_KLASS")
59
+ ENV.delete("PWWKA_QUEUE_EXTENDED_INFO")
34
60
  end
35
61
  end
36
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pwwka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0.RC1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stitch Fix Engineering
@@ -15,7 +15,7 @@ authors:
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
- date: 2017-06-12 00:00:00.000000000 Z
18
+ date: 2017-08-29 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bunny
@@ -254,12 +254,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
254
254
  version: '0'
255
255
  required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  requirements:
257
- - - ">="
257
+ - - ">"
258
258
  - !ruby/object:Gem::Version
259
- version: '0'
259
+ version: 1.3.1
260
260
  requirements: []
261
261
  rubyforge_project:
262
- rubygems_version: 2.6.11
262
+ rubygems_version: 2.6.13
263
263
  signing_key:
264
264
  specification_version: 4
265
265
  summary: Send and receive messages via RabbitMQ