pwwka 0.12.0.RC1 → 0.12.0.RC2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -2
- data/lib/pwwka/queue_resque_job_handler.rb +12 -2
- data/lib/pwwka/version.rb +1 -1
- data/spec/unit/queue_resque_job_handler_spec.rb +24 -6
- 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: d2a01012af3050ef6e214e57b4831e9953c7296c
|
4
|
+
data.tar.gz: 0cf0a7b780a9b91b83ee2824d4dc5ffc747f58a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10be7d442840c8a0d676ae60a91817383cac3dae1a76273c669229d32e1666c064acd1426da4e457ebed66473f196985d2134d8c07f541bf7ab1dc9713d054cc
|
7
|
+
data.tar.gz: c63039a9bac0ca399296694312c40bf430063e610880b1a5c2956437ad224eaa94dda85373da54229a62eab9e60ed94c930d33f4d35912335bf24faedcac2dc7
|
data/Gemfile.lock
CHANGED
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
|
304
|
+
my_handler: rake message_handler:receive HANDLER_KLASS=Pwwka::QueueResqueJobHandler JOB_KLASS=MyResqueJob 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.
|
@@ -322,7 +322,8 @@ If you use [Resque][resque], and you wish to handle messages in a resque job, yo
|
|
322
322
|
|
323
323
|
Note that you must provide `@queue` in your job. `QueueResqueJobHandler` doesn't support setting a custom queue at enqueue-time (PRs welcome :).
|
324
324
|
|
325
|
-
Note that if you were using this library before version 0.12.0, your job would only be given the payload.
|
325
|
+
Note that if you were using this library before version 0.12.0, your job would only be given the payload. If you change your job to accept exatly three arguments, you will be given the payload, routing key, and message properties. If any of those arguments are optional, you will need to set `PWWKA_QUEUE_EXTENDED_INFO` to `"true"` to force pwwka to pass those along. Without it, your job only gets the payload to avoid breaking legacy consumers.
|
326
|
+
|
326
327
|
3. Profit!
|
327
328
|
|
328
329
|
[resque]: https://github.com/resque/resque/tree/1-x-stable
|
@@ -15,15 +15,25 @@ module Pwwka
|
|
15
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.
|
16
16
|
class QueueResqueJobHandler
|
17
17
|
def self.handle!(delivery_info,properties,payload)
|
18
|
+
job_klass = ENV["JOB_KLASS"].constantize
|
18
19
|
args = [
|
19
|
-
|
20
|
+
job_klass,
|
20
21
|
payload
|
21
22
|
]
|
22
|
-
if ENV["PWWKA_QUEUE_EXTENDED_INFO"] == 'true'
|
23
|
+
if ENV["PWWKA_QUEUE_EXTENDED_INFO"] == 'true' || job_klass_can_handle_args?(job_klass)
|
23
24
|
args << delivery_info.routing_key
|
24
25
|
args << properties.to_hash
|
25
26
|
end
|
26
27
|
Resque.enqueue(*args)
|
27
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.job_klass_can_handle_args?(job_klass)
|
33
|
+
method = job_klass.method(:perform)
|
34
|
+
return false if method.nil?
|
35
|
+
method.arity == 3
|
36
|
+
end
|
28
37
|
end
|
38
|
+
|
29
39
|
end
|
data/lib/pwwka/version.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'pwwka/queue_resque_job_handler'
|
3
3
|
|
4
|
-
class
|
4
|
+
class MyLegacyTestJob
|
5
|
+
def self.perform(payload)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class MyNewTestJob
|
10
|
+
def self.perform(payload, routing_key, properties)
|
11
|
+
end
|
5
12
|
end
|
6
13
|
|
7
14
|
describe Pwwka::QueueResqueJobHandler do
|
8
15
|
|
9
16
|
describe "::handle!" do
|
10
|
-
let(:job_class) {
|
17
|
+
let(:job_class) { MyLegacyTestJob }
|
11
18
|
let(:routing_key) { "foo.bar.blah" }
|
12
19
|
let(:delivery_info) { double("delivery info", routing_key: routing_key) }
|
13
20
|
let(:properties_hash) {
|
@@ -28,13 +35,13 @@ describe Pwwka::QueueResqueJobHandler do
|
|
28
35
|
|
29
36
|
before do
|
30
37
|
allow(Resque).to receive(:enqueue)
|
31
|
-
ENV["JOB_KLASS"] =
|
38
|
+
ENV["JOB_KLASS"] = MyLegacyTestJob.name
|
32
39
|
end
|
33
40
|
|
34
41
|
context "when not asking for more information explicitly" do
|
35
42
|
it "should queue a resque job using JOB_KLASS and the payload" do
|
36
43
|
described_class.handle!(delivery_info,properties,payload)
|
37
|
-
expect(Resque).to have_received(:enqueue).with(
|
44
|
+
expect(Resque).to have_received(:enqueue).with(MyLegacyTestJob,payload)
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
@@ -42,15 +49,26 @@ describe Pwwka::QueueResqueJobHandler do
|
|
42
49
|
it "should queue a resque job using JOB_KLASS and the payload" do
|
43
50
|
ENV["PWWKA_QUEUE_EXTENDED_INFO"] = 'false'
|
44
51
|
described_class.handle!(delivery_info,properties,payload)
|
45
|
-
expect(Resque).to have_received(:enqueue).with(
|
52
|
+
expect(Resque).to have_received(:enqueue).with(MyLegacyTestJob,payload)
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
49
56
|
context "when asking for more information via PWWKA_QUEUE_EXTENDED_INFO" do
|
50
57
|
it "should queue a resque job using JOB_KLASS, payload, routing key, and properties as a hash" do
|
58
|
+
# Note, using MyLegacyTestJob to ensure this doesn't trigger the method param examination logic and respects
|
59
|
+
# the env var, even though it is not used correctly in this case.
|
51
60
|
ENV["PWWKA_QUEUE_EXTENDED_INFO"] = 'true'
|
52
61
|
described_class.handle!(delivery_info,properties,payload)
|
53
|
-
expect(Resque).to have_received(:enqueue).with(
|
62
|
+
expect(Resque).to have_received(:enqueue).with(MyLegacyTestJob,payload,routing_key,properties_hash)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when not asking for more information via PWWKA_QUEUE_EXTENDED_INFO but for a job that can handle it" do
|
67
|
+
it "should queue a resque job using JOB_KLASS, payload, routing key, and properties as a hash" do
|
68
|
+
ENV["JOB_KLASS"] = MyNewTestJob.name
|
69
|
+
ENV.delete("PWWKA_QUEUE_EXTENDED_INFO")
|
70
|
+
described_class.handle!(delivery_info,properties,payload)
|
71
|
+
expect(Resque).to have_received(:enqueue).with(MyNewTestJob,payload,routing_key,properties_hash)
|
54
72
|
end
|
55
73
|
end
|
56
74
|
|
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.12.0.
|
4
|
+
version: 0.12.0.RC2
|
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-08-
|
18
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: bunny
|