resque-bus 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resque-bus.rb +15 -1
- data/lib/resque_bus/version.rb +1 -1
- data/spec/driver_spec.rb +3 -12
- data/spec/publish_spec.rb +23 -2
- data/spec/subscriber_spec.rb +7 -7
- metadata +2 -2
data/lib/resque-bus.rb
CHANGED
@@ -146,6 +146,17 @@ module ResqueBus
|
|
146
146
|
I18n.locale = original_locale unless original_locale == false
|
147
147
|
Time.zone = original_timezone unless original_timezone == false
|
148
148
|
end
|
149
|
+
|
150
|
+
def before_publish=(proc)
|
151
|
+
@before_publish_callback = proc
|
152
|
+
end
|
153
|
+
|
154
|
+
def before_publish_callback(attributes)
|
155
|
+
if @before_publish_callback
|
156
|
+
@before_publish_callback.call(attributes)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
149
160
|
|
150
161
|
def publish_metadata(event_type, attributes={})
|
151
162
|
# TODO: "bus_app_key" => application.app_key ?
|
@@ -154,7 +165,9 @@ module ResqueBus
|
|
154
165
|
bus_attr["bus_app_hostname"] = hostname
|
155
166
|
bus_attr["bus_locale"] = I18n.locale.to_s if defined?(I18n) && I18n.respond_to?(:locale) && I18n.locale
|
156
167
|
bus_attr["bus_timezone"] = Time.zone.name if defined?(Time) && Time.respond_to?(:zone) && Time.zone
|
157
|
-
bus_attr.merge(attributes || {})
|
168
|
+
out = bus_attr.merge(attributes || {})
|
169
|
+
ResqueBus.before_publish_callback(out)
|
170
|
+
out
|
158
171
|
end
|
159
172
|
|
160
173
|
def generate_uuid
|
@@ -224,6 +237,7 @@ module ResqueBus
|
|
224
237
|
@dispatcher = nil
|
225
238
|
@default_app_key = nil
|
226
239
|
@default_queue = nil
|
240
|
+
@before_publish_callback = nil
|
227
241
|
end
|
228
242
|
|
229
243
|
def incoming_queue
|
data/lib/resque_bus/version.rb
CHANGED
data/spec/driver_spec.rb
CHANGED
@@ -80,20 +80,11 @@ module ResqueBus
|
|
80
80
|
|
81
81
|
hash = JSON.parse(ResqueBus.redis.lpop("queue:default"))
|
82
82
|
hash["class"].should == "::ResqueBus::Rider"
|
83
|
-
hash["args"][0].should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"
|
84
|
-
|
85
|
-
|
83
|
+
hash["args"][0].should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event[45]", "bus_rider_queue" => "default"}.merge(bus_attrs)
|
84
|
+
|
86
85
|
hash = JSON.parse(ResqueBus.redis.lpop("queue:default"))
|
87
86
|
hash["class"].should == "::ResqueBus::Rider"
|
88
|
-
hash["args"][0].should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"
|
89
|
-
second= hash["args"][0]["bus_rider_sub_key"]
|
90
|
-
|
91
|
-
if first == "event[45]"
|
92
|
-
second.should == "event5"
|
93
|
-
else
|
94
|
-
first.should == "event5"
|
95
|
-
second.should == "event[45]"
|
96
|
-
end
|
87
|
+
hash["args"][0].should == {"bus_rider_app_key"=>"app3", "x" => "y", "bus_event_type" => "event5", "bus_rider_sub_key"=>"event5", "bus_rider_queue" => "default"}.merge(bus_attrs)
|
97
88
|
end
|
98
89
|
end
|
99
90
|
end
|
data/spec/publish_spec.rb
CHANGED
@@ -44,16 +44,37 @@ describe "Publishing an event" do
|
|
44
44
|
hash["args"].should == [ {"bus_event_type" => event_name, "two"=>"here", "one"=>1}.merge(bus_attrs).merge("bus_id" => 'app-given') ]
|
45
45
|
end
|
46
46
|
|
47
|
+
it "should add metadata via callback" do
|
48
|
+
myval = 0
|
49
|
+
ResqueBus.before_publish = lambda { |att|
|
50
|
+
att["mine"] = 4
|
51
|
+
myval += 1
|
52
|
+
}
|
47
53
|
|
54
|
+
hash = {:one => 1, "two" => "here", "bus_id" => "app-given" }
|
55
|
+
event_name = "event_name"
|
56
|
+
|
57
|
+
val = ResqueBus.redis.lpop("queue:resquebus_incoming")
|
58
|
+
val.should == nil
|
59
|
+
|
60
|
+
ResqueBus.publish(event_name, hash)
|
61
|
+
|
62
|
+
|
63
|
+
val = ResqueBus.redis.lpop("queue:resquebus_incoming")
|
64
|
+
hash = JSON.parse(val)
|
65
|
+
att = hash["args"].first
|
66
|
+
att["mine"].should == 4
|
67
|
+
myval.should == 1
|
68
|
+
end
|
48
69
|
|
49
70
|
it "should set the timezone and locale if available" do
|
50
71
|
defined?(I18n).should be_nil
|
51
72
|
Time.respond_to?(:zone).should be_false
|
52
73
|
|
53
74
|
stub_const("I18n", Class.new)
|
54
|
-
I18n.
|
75
|
+
I18n.stub(:locale).and_return("jp")
|
55
76
|
|
56
|
-
Time.
|
77
|
+
Time.stub(:zone).and_return(double('zone', :name => "EST"))
|
57
78
|
|
58
79
|
hash = {:one => 1, "two" => "here", "bus_id" => "app-given" }
|
59
80
|
event_name = "event_name"
|
data/spec/subscriber_spec.rb
CHANGED
@@ -190,22 +190,22 @@ module ResqueBus
|
|
190
190
|
|
191
191
|
hash = JSON.parse(ResqueBus.redis.lpop("queue:myqueue"))
|
192
192
|
hash["class"].should == "SubscriberTest1"
|
193
|
-
hash["args"].should == [ {"bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.
|
193
|
+
hash["args"].should == [ {"bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.thing_filter", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
|
194
194
|
"bus_event_type" => "event_sub", "x" => "y"}.merge(bus_attrs) ]
|
195
195
|
|
196
196
|
Runner1.value.should == 0
|
197
197
|
Runner2.value.should == 0
|
198
198
|
Util.constantize(hash["class"]).perform(*hash["args"])
|
199
|
-
Runner1.value.should ==
|
200
|
-
Runner2.value.should ==
|
199
|
+
Runner1.value.should == 0
|
200
|
+
Runner2.value.should == 1
|
201
201
|
|
202
202
|
hash = JSON.parse(ResqueBus.redis.lpop("queue:myqueue"))
|
203
203
|
hash["class"].should == "SubscriberTest1"
|
204
|
-
hash["args"].should == [ {"bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.
|
204
|
+
hash["args"].should == [ {"bus_rider_app_key"=>"my_thing", "bus_rider_sub_key"=>"SubscriberTest1.event_sub", "bus_rider_queue" => "myqueue", "bus_rider_class_name"=>"SubscriberTest1",
|
205
205
|
"bus_event_type" => "event_sub", "x" => "y"}.merge(bus_attrs) ]
|
206
|
-
|
207
|
-
Runner1.value.should ==
|
208
|
-
Runner2.value.should ==
|
206
|
+
|
207
|
+
Runner1.value.should == 0
|
208
|
+
Runner2.value.should == 1
|
209
209
|
Util.constantize(hash["class"]).perform(*hash["args"])
|
210
210
|
Runner1.value.should == 1
|
211
211
|
Runner2.value.should == 1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|