resque-bus 0.3.7 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +2 -2
- data/README.mdown +42 -64
- data/Rakefile +0 -1
- data/lib/resque-bus.rb +13 -305
- data/lib/resque_bus/adapter.rb +65 -0
- data/lib/resque_bus/compatibility/deprecated.rb +38 -0
- data/lib/resque_bus/compatibility/driver.rb +10 -0
- data/lib/resque_bus/compatibility/heartbeat.rb +10 -0
- data/lib/resque_bus/compatibility/publisher.rb +13 -0
- data/lib/resque_bus/compatibility/rider.rb +32 -0
- data/lib/resque_bus/compatibility/subscriber.rb +8 -0
- data/lib/resque_bus/compatibility/task_manager.rb +8 -0
- data/lib/resque_bus/server/views/bus.erb +2 -2
- data/lib/resque_bus/server.rb +5 -4
- data/lib/resque_bus/tasks.rb +46 -46
- data/lib/resque_bus/version.rb +2 -4
- data/resque-bus.gemspec +5 -10
- data/spec/adapter/compatibility_spec.rb +97 -0
- data/spec/adapter/integration_spec.rb +111 -0
- data/spec/adapter/publish_at_spec.rb +50 -0
- data/spec/adapter/retry_spec.rb +47 -0
- data/spec/adapter/support.rb +23 -0
- data/spec/adapter_spec.rb +14 -0
- data/spec/application_spec.rb +62 -62
- data/spec/config_spec.rb +83 -0
- data/spec/dispatch_spec.rb +6 -6
- data/spec/driver_spec.rb +62 -44
- data/spec/heartbeat_spec.rb +4 -4
- data/spec/integration_spec.rb +2 -2
- data/spec/matcher_spec.rb +29 -29
- data/spec/publish_spec.rb +46 -43
- data/spec/publisher_spec.rb +7 -0
- data/spec/rider_spec.rb +14 -66
- data/spec/spec_helper.rb +25 -25
- data/spec/subscriber_spec.rb +194 -176
- data/spec/subscription_list_spec.rb +1 -1
- data/spec/subscription_spec.rb +1 -1
- data/spec/worker_spec.rb +32 -0
- metadata +47 -58
- data/lib/resque_bus/application.rb +0 -115
- data/lib/resque_bus/compatibility.rb +0 -24
- data/lib/resque_bus/dispatch.rb +0 -61
- data/lib/resque_bus/driver.rb +0 -30
- data/lib/resque_bus/heartbeat.rb +0 -106
- data/lib/resque_bus/local.rb +0 -38
- data/lib/resque_bus/matcher.rb +0 -81
- data/lib/resque_bus/publisher.rb +0 -12
- data/lib/resque_bus/rider.rb +0 -54
- data/lib/resque_bus/subscriber.rb +0 -63
- data/lib/resque_bus/subscription.rb +0 -55
- data/lib/resque_bus/subscription_list.rb +0 -53
- data/lib/resque_bus/task_manager.rb +0 -52
- data/lib/resque_bus/util.rb +0 -42
- data/lib/tasks/resquebus.rake +0 -2
- data/spec/compatibility_spec.rb +0 -93
- data/spec/publish_at_spec.rb +0 -74
- data/spec/redis_spec.rb +0 -13
@@ -0,0 +1,13 @@
|
|
1
|
+
module ResqueBus
|
2
|
+
# publishes on a delay
|
3
|
+
class Publisher
|
4
|
+
class << self
|
5
|
+
def perform(event_type, attributes = {})
|
6
|
+
attributes["bus_event_type"] = event_type # now using one hash only
|
7
|
+
ResqueBus.note_deprecation "[MIGRATION] Note: new events will be using QueueBus::Publisher"
|
8
|
+
::QueueBus::Publisher.perform(attributes)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'resque-retry'
|
2
|
+
|
3
|
+
module ResqueBus
|
4
|
+
class Rider
|
5
|
+
extend Resque::Plugins::ExponentialBackoff
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def perform(attributes = {})
|
9
|
+
ResqueBus.note_deprecation "[MIGRATION] Note: new events will be using QueueBus::Rider"
|
10
|
+
::QueueBus::Rider.perform(attributes)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @failure_hooks_already_ran on https://github.com/defunkt/resque/tree/1-x-stable
|
14
|
+
# to prevent running twice
|
15
|
+
def queue
|
16
|
+
@my_queue
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_failure_aaa(exception, *args)
|
20
|
+
# note: sorted alphabetically
|
21
|
+
# queue needs to be set for rety to work (know what queue in Requeue.class_to_queue)
|
22
|
+
@my_queue = args[0]["bus_rider_queue"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def on_failure_zzz(exception, *args)
|
26
|
+
# note: sorted alphabetically
|
27
|
+
@my_queue = nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -18,7 +18,7 @@ else
|
|
18
18
|
event_hash = {}
|
19
19
|
|
20
20
|
# collect each differently
|
21
|
-
|
21
|
+
::QueueBus::Application.all.each do |app|
|
22
22
|
app_key = app.app_key
|
23
23
|
|
24
24
|
app_hash[app_key] ||= []
|
@@ -61,7 +61,7 @@ else
|
|
61
61
|
else
|
62
62
|
one, two, queue, filters = val
|
63
63
|
out = "<td>#{h(one)}</td><td>#{h(two)}</td><td><a href='#{u("queues/#{queue}")}'>#{h(queue)}</a></td>"
|
64
|
-
out << "<td>#{h(
|
64
|
+
out << "<td>#{h(::QueueBus::Util.encode(filters).gsub(/\"bus_special_value_(\w+)\"/){ "(#{$1})" }).gsub(" ", " ").gsub('","', '", "')}</td>"
|
65
65
|
end
|
66
66
|
|
67
67
|
if first
|
data/lib/resque_bus/server.rb
CHANGED
@@ -2,7 +2,8 @@ require 'resque-bus'
|
|
2
2
|
require 'resque/server'
|
3
3
|
require 'erb'
|
4
4
|
|
5
|
-
#
|
5
|
+
# MIGRATE TODO: move to resque gem
|
6
|
+
# Extend ::Resque::Server to add tabs.
|
6
7
|
module ResqueBus
|
7
8
|
module Server
|
8
9
|
|
@@ -24,7 +25,7 @@ module ResqueBus
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
Resque::Server.tabs << 'Bus'
|
28
|
-
Resque::Server.class_eval do
|
29
|
-
include ResqueBus::Server
|
28
|
+
::Resque::Server.tabs << 'Bus'
|
29
|
+
::Resque::Server.class_eval do
|
30
|
+
include ::ResqueBus::Server
|
30
31
|
end
|
data/lib/resque_bus/tasks.rb
CHANGED
@@ -1,15 +1,35 @@
|
|
1
|
-
# require '
|
2
|
-
# will give you
|
3
|
-
|
1
|
+
# require 'resque_bus/tasks'
|
2
|
+
# will give you these tasks
|
4
3
|
|
4
|
+
require "queue_bus/tasks"
|
5
5
|
require "resque/tasks"
|
6
|
+
|
6
7
|
namespace :resquebus do
|
8
|
+
# deprecated
|
9
|
+
task :setup => ["queuebus:setup"] do
|
10
|
+
ResqueBus.note_deprecation "[DEPRECATION] rake resquebus:setup is deprecated. Use rake queuebus:setup instead."
|
11
|
+
end
|
12
|
+
|
13
|
+
task :driver => ["queuebus:driver"] do
|
14
|
+
ResqueBus.note_deprecation "[DEPRECATION] rake resquebus:driver is deprecated. Use rake queuebus:driver instead."
|
15
|
+
end
|
16
|
+
|
17
|
+
task :subscribe => ["queuebus:subscribe"] do
|
18
|
+
ResqueBus.note_deprecation "[DEPRECATION] rake resquebus:subscribe is deprecated. Use rake queuebus:subscribe instead."
|
19
|
+
end
|
20
|
+
|
21
|
+
task :unsubsribe => ["queuebus:unsubsribe"] do
|
22
|
+
ResqueBus.note_deprecation "[DEPRECATION] rake resquebus:driver is deprecated. Use rake queuebus:unsubsribe instead."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
namespace :queuebus do
|
7
27
|
|
8
28
|
desc "Setup will configure a resque task to run before resque:work"
|
9
29
|
task :setup => [ :preload ] do
|
10
|
-
|
30
|
+
|
11
31
|
if ENV['QUEUES'].nil?
|
12
|
-
manager = ::
|
32
|
+
manager = ::QueueBus::TaskManager.new(true)
|
13
33
|
queues = manager.queue_names
|
14
34
|
ENV['QUEUES'] = queues.join(",")
|
15
35
|
else
|
@@ -23,24 +43,9 @@ namespace :resquebus do
|
|
23
43
|
end
|
24
44
|
end
|
25
45
|
|
26
|
-
desc "
|
27
|
-
task :subscribe => [ :preload ] do
|
28
|
-
manager = ::ResqueBus::TaskManager.new(true)
|
29
|
-
count = manager.subscribe!
|
30
|
-
raise "No subscriptions created" if count == 0
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Unsubscribes this application from ResqueBus events"
|
34
|
-
task :unsubscribe => [ :preload ] do
|
35
|
-
require 'resque-bus'
|
36
|
-
manager = ::ResqueBus::TaskManager.new(true)
|
37
|
-
count = manager.unsubscribe!
|
38
|
-
puts "No subscriptions unsubscribed" if count == 0
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "Sets the queue to work the driver Use: `rake resquebus:driver resque:work`"
|
46
|
+
desc "Sets the queue to work the driver Use: `rake queuebus:driver resque:work`"
|
42
47
|
task :driver => [ :preload ] do
|
43
|
-
ENV['QUEUES'] =
|
48
|
+
ENV['QUEUES'] = ::QueueBus.incoming_queue
|
44
49
|
end
|
45
50
|
|
46
51
|
# Preload app files if this is Rails
|
@@ -50,32 +55,27 @@ namespace :resquebus do
|
|
50
55
|
require "resque/failure/redis"
|
51
56
|
require "resque/failure/multiple_with_retry_suppression"
|
52
57
|
|
53
|
-
# change the namespace to be the ones used by ResqueBus
|
54
|
-
# save the old one for handling later
|
55
|
-
ResqueBus.original_redis = Resque.redis
|
56
|
-
Resque.redis = ResqueBus.redis
|
57
|
-
|
58
58
|
Resque::Failure::MultipleWithRetrySuppression.classes = [Resque::Failure::Redis]
|
59
59
|
Resque::Failure.backend = Resque::Failure::MultipleWithRetrySuppression
|
60
|
-
|
60
|
+
|
61
61
|
Rake::Task["resque:setup"].invoke # loads the environment and such if defined
|
62
62
|
end
|
63
|
-
|
64
|
-
|
63
|
+
|
64
|
+
|
65
65
|
# examples to test out the system
|
66
66
|
namespace :example do
|
67
67
|
desc "Publishes events to example applications"
|
68
|
-
task :publish => [ "
|
68
|
+
task :publish => [ "queuebus:preload", "queuebus:setup" ] do
|
69
69
|
which = ["one", "two", "three", "other"][rand(4)]
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
QueueBus.publish("event_#{which}", { "rand" => rand(99999)})
|
71
|
+
QueueBus.publish("event_all", { "rand" => rand(99999)})
|
72
|
+
QueueBus.publish("none_subscribed", { "rand" => rand(99999)})
|
73
73
|
puts "published event_#{which}, event_all, none_subscribed"
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
desc "Sets up an example config"
|
77
|
-
task :register => [ "
|
78
|
-
|
77
|
+
task :register => [ "queuebus:preload"] do
|
78
|
+
QueueBus.dispatch("example") do
|
79
79
|
subscribe "event_one" do
|
80
80
|
puts "event1 happened"
|
81
81
|
end
|
@@ -93,14 +93,14 @@ namespace :resquebus do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
97
|
-
desc "Subscribes this application to
|
98
|
-
task :subscribe => [ :register, "
|
99
|
-
|
100
|
-
desc "Start a
|
101
|
-
task :work => [ :register, "
|
102
|
-
|
103
|
-
desc "Start a
|
104
|
-
task :driver => [ :register, "
|
96
|
+
|
97
|
+
desc "Subscribes this application to QueueBus example events"
|
98
|
+
task :subscribe => [ :register, "queuebus:subscribe" ]
|
99
|
+
|
100
|
+
desc "Start a QueueBus example worker"
|
101
|
+
task :work => [ :register, "queuebus:setup", "resque:work" ]
|
102
|
+
|
103
|
+
desc "Start a QueueBus example worker"
|
104
|
+
task :driver => [ :register, "queuebus:driver", "resque:work" ]
|
105
105
|
end
|
106
106
|
end
|
data/lib/resque_bus/version.rb
CHANGED
data/resque-bus.gemspec
CHANGED
@@ -4,13 +4,12 @@ require "resque_bus/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "resque-bus"
|
7
|
-
s.version =
|
7
|
+
s.version = ResqueBus::VERSION
|
8
8
|
s.authors = ["Brian Leonard"]
|
9
9
|
s.email = ["brian@bleonard.com"]
|
10
|
-
s.homepage = ""
|
10
|
+
s.homepage = "https://github.com/queue-bus/resque-bus"
|
11
11
|
s.summary = %q{A simple event bus on top of Resque}
|
12
|
-
s.description = %q{A simple event bus on top of Resque.
|
13
|
-
Publish and subscribe to events as they occur through a queue.}
|
12
|
+
s.description = %q{A simple event bus on top of Resque. Publish and subscribe to events as they occur through a queue.}
|
14
13
|
|
15
14
|
s.rubyforge_project = "resque-bus"
|
16
15
|
|
@@ -19,15 +18,11 @@ Gem::Specification.new do |s|
|
|
19
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
19
|
s.require_paths = ["lib"]
|
21
20
|
|
22
|
-
|
23
|
-
# s.add_development_dependency "rspec"
|
24
|
-
# s.add_runtime_dependency "rest-client"
|
21
|
+
s.add_dependency('queue-bus', '0.5.5')
|
25
22
|
s.add_dependency('resque', ['>= 1.10.0', '< 2.0'])
|
26
23
|
s.add_dependency('resque-scheduler', '>= 2.0.1')
|
27
24
|
s.add_dependency('resque-retry')
|
28
|
-
|
29
|
-
s.add_dependency("redis")
|
30
|
-
|
25
|
+
|
31
26
|
s.add_development_dependency("rspec")
|
32
27
|
s.add_development_dependency("timecop")
|
33
28
|
s.add_development_dependency("json_pure")
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Compatibility with old resque-bus" do
|
4
|
+
before(:each) do
|
5
|
+
ResqueBus.show_deprecations = false # expected
|
6
|
+
|
7
|
+
QueueBus.dispatch("r1") do
|
8
|
+
subscribe "event_name" do |attributes|
|
9
|
+
QueueBus::Runner1.run(attributes)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
QueueBus::TaskManager.new(false).subscribe!
|
14
|
+
|
15
|
+
@incoming = Resque::Worker.new(:resquebus_incoming)
|
16
|
+
@incoming.register_worker
|
17
|
+
|
18
|
+
@new_incoming = Resque::Worker.new(:bus_incoming)
|
19
|
+
@new_incoming.register_worker
|
20
|
+
|
21
|
+
@rider = Resque::Worker.new(:r1_default)
|
22
|
+
@rider.register_worker
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Publisher" do
|
26
|
+
it "should still publish as expected" do
|
27
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:resquebus_incoming") }
|
28
|
+
val.should == nil
|
29
|
+
|
30
|
+
args = [ "event_name", {"bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12} ]
|
31
|
+
item = {:class => "ResqueBus::Publisher", :args => args}
|
32
|
+
|
33
|
+
QueueBus.redis { |redis| redis.sadd(:queues, "resquebus_incoming") }
|
34
|
+
QueueBus.redis { |redis| redis.rpush "queue:resquebus_incoming", Resque.encode(item) }
|
35
|
+
|
36
|
+
QueueBus::Runner1.value.should == 0
|
37
|
+
|
38
|
+
perform_next_job @incoming # publish
|
39
|
+
|
40
|
+
QueueBus::Runner1.value.should == 0
|
41
|
+
|
42
|
+
perform_next_job @new_incoming # drive
|
43
|
+
|
44
|
+
QueueBus::Runner1.value.should == 0
|
45
|
+
|
46
|
+
perform_next_job @rider # ride
|
47
|
+
|
48
|
+
QueueBus::Runner1.value.should == 1
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "Rider" do
|
54
|
+
it "should still ride as expected" do
|
55
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:r1_default") }
|
56
|
+
val.should == nil
|
57
|
+
|
58
|
+
args = [ {"bus_rider_app_key"=>"r1", "x" => "y", "bus_event_type" => "event_name",
|
59
|
+
"bus_rider_sub_key"=>"event_name", "bus_rider_queue" => "default",
|
60
|
+
"bus_rider_class_name"=>"::ResqueBus::Rider"}]
|
61
|
+
item = {:class => "ResqueBus::Rider", :args => args}
|
62
|
+
|
63
|
+
QueueBus.redis { |redis| redis.sadd(:queues, "r1_default") }
|
64
|
+
QueueBus.redis { |redis| redis.rpush "queue:r1_default", Resque.encode(item) }
|
65
|
+
|
66
|
+
QueueBus::Runner1.value.should == 0
|
67
|
+
|
68
|
+
perform_next_job @rider
|
69
|
+
|
70
|
+
QueueBus::Runner1.value.should == 1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "Driver" do
|
75
|
+
it "should still drive as expected" do
|
76
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:resquebus_incoming") }
|
77
|
+
val.should == nil
|
78
|
+
|
79
|
+
args = [ {"bus_event_type" => "event_name", "two"=>"here", "one"=>1, "id" => 12} ]
|
80
|
+
item = {:class => "ResqueBus::Driver", :args => args}
|
81
|
+
|
82
|
+
QueueBus.redis { |redis| redis.sadd(:queues, "resquebus_incoming") }
|
83
|
+
QueueBus.redis { |redis| redis.rpush "queue:resquebus_incoming", Resque.encode(item) }
|
84
|
+
|
85
|
+
QueueBus::Runner1.value.should == 0
|
86
|
+
|
87
|
+
perform_next_job @incoming
|
88
|
+
|
89
|
+
QueueBus::Runner1.value.should == 0
|
90
|
+
|
91
|
+
perform_next_job @rider
|
92
|
+
|
93
|
+
QueueBus::Runner1.value.should == 1
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Resque Integration" do
|
4
|
+
describe "Happy Path" do
|
5
|
+
before(:each) do
|
6
|
+
QueueBus.dispatch("r1") do
|
7
|
+
subscribe "event_name" do |attributes|
|
8
|
+
QueueBus::Runner1.run(attributes)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
QueueBus::TaskManager.new(false).subscribe!
|
13
|
+
|
14
|
+
@incoming = Resque::Worker.new(:bus_incoming)
|
15
|
+
@incoming.register_worker
|
16
|
+
|
17
|
+
@rider = Resque::Worker.new(:r1_default)
|
18
|
+
@rider.register_worker
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should publish and receive" do
|
22
|
+
QueueBus::Runner1.value.should == 0
|
23
|
+
|
24
|
+
QueueBus.publish("event_name", "ok" => true)
|
25
|
+
QueueBus::Runner1.value.should == 0
|
26
|
+
|
27
|
+
perform_next_job @incoming
|
28
|
+
|
29
|
+
QueueBus::Runner1.value.should == 0
|
30
|
+
|
31
|
+
perform_next_job @rider
|
32
|
+
|
33
|
+
QueueBus::Runner1.value.should == 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Delayed Publishing" do
|
38
|
+
before(:each) do
|
39
|
+
Timecop.freeze(now)
|
40
|
+
QueueBus.stub(:generate_uuid).and_return("idfhlkj")
|
41
|
+
end
|
42
|
+
after(:each) do
|
43
|
+
Timecop.return
|
44
|
+
end
|
45
|
+
let(:delayed_attrs) { {"bus_delayed_until" => future.to_i,
|
46
|
+
"bus_id" => "#{now.to_i}-idfhlkj",
|
47
|
+
"bus_app_hostname" => `hostname 2>&1`.strip.sub(/.local/,'')} }
|
48
|
+
|
49
|
+
let(:bus_attrs) { delayed_attrs.merge({"bus_published_at" => worktime.to_i})}
|
50
|
+
let(:now) { Time.parse("01/01/2013 5:00")}
|
51
|
+
let(:future) { Time.at(now.to_i + 60) }
|
52
|
+
let(:worktime) {Time.at(future.to_i + 1)}
|
53
|
+
|
54
|
+
it "should add it to Redis" do
|
55
|
+
hash = {:one => 1, "two" => "here", "id" => 12 }
|
56
|
+
event_name = "event_name"
|
57
|
+
QueueBus.publish_at(future, event_name, hash)
|
58
|
+
|
59
|
+
schedule = QueueBus.redis { |redis| redis.zrange("delayed_queue_schedule", 0, 1) }
|
60
|
+
schedule.should == [future.to_i.to_s]
|
61
|
+
|
62
|
+
val = QueueBus.redis { |redis| redis.lpop("delayed:#{future.to_i}") }
|
63
|
+
hash = JSON.parse(val)
|
64
|
+
|
65
|
+
hash["class"].should == "QueueBus::Worker"
|
66
|
+
hash["args"].size.should == 1
|
67
|
+
JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs)
|
68
|
+
hash["queue"].should == "bus_incoming"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should move it to the real queue when processing" do
|
72
|
+
hash = {:one => 1, "two" => "here", "id" => 12 }
|
73
|
+
event_name = "event_name"
|
74
|
+
|
75
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
76
|
+
val.should == nil
|
77
|
+
|
78
|
+
QueueBus.publish_at(future, event_name, hash)
|
79
|
+
|
80
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
81
|
+
val.should == nil # nothing really added
|
82
|
+
|
83
|
+
# process sceduler now
|
84
|
+
Resque::Scheduler.handle_delayed_items
|
85
|
+
|
86
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
87
|
+
val.should == nil # nothing added yet
|
88
|
+
|
89
|
+
# process scheduler in future
|
90
|
+
Timecop.freeze(worktime) do
|
91
|
+
Resque::Scheduler.handle_delayed_items
|
92
|
+
|
93
|
+
# added
|
94
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
95
|
+
hash = JSON.parse(val)
|
96
|
+
hash["class"].should == "QueueBus::Worker"
|
97
|
+
hash["args"].size.should == 1
|
98
|
+
JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs)
|
99
|
+
|
100
|
+
QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
|
101
|
+
|
102
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
103
|
+
hash = JSON.parse(val)
|
104
|
+
hash["class"].should == "QueueBus::Worker"
|
105
|
+
hash["args"].size.should == 1
|
106
|
+
JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Publishing an event in the future" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
Timecop.freeze(now)
|
7
|
+
QueueBus.stub(:generate_uuid).and_return("idfhlkj")
|
8
|
+
end
|
9
|
+
after(:each) do
|
10
|
+
Timecop.return
|
11
|
+
end
|
12
|
+
let(:delayed_attrs) { {"bus_delayed_until" => future.to_i,
|
13
|
+
"bus_id" => "#{now.to_i}-idfhlkj",
|
14
|
+
"bus_app_hostname" => `hostname 2>&1`.strip.sub(/.local/,'')} }
|
15
|
+
|
16
|
+
let(:bus_attrs) { delayed_attrs.merge({"bus_published_at" => worktime.to_i})}
|
17
|
+
let(:now) { Time.parse("01/01/2013 5:00")}
|
18
|
+
let(:future) { Time.at(now.to_i + 60) }
|
19
|
+
let(:worktime) {Time.at(future.to_i + 1)}
|
20
|
+
|
21
|
+
it "should add it to Redis then to the real queue" do
|
22
|
+
hash = {:one => 1, "two" => "here", "id" => 12 }
|
23
|
+
event_name = "event_name"
|
24
|
+
QueueBus.publish_at(future, event_name, hash)
|
25
|
+
|
26
|
+
schedule = QueueBus.redis { |redis| redis.zrange("delayed_queue_schedule", 0, 1) }
|
27
|
+
schedule.should == [future.to_i.to_s]
|
28
|
+
|
29
|
+
val = QueueBus.redis { |redis| redis.lpop("delayed:#{future.to_i}") }
|
30
|
+
hash = JSON.parse(val)
|
31
|
+
|
32
|
+
hash["class"].should == "QueueBus::Worker"
|
33
|
+
hash["args"].size.should == 1
|
34
|
+
JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs)
|
35
|
+
hash["queue"].should == "bus_incoming"
|
36
|
+
|
37
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
38
|
+
val.should == nil # nothing really added
|
39
|
+
|
40
|
+
Timecop.freeze(worktime)
|
41
|
+
QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
|
42
|
+
|
43
|
+
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
|
44
|
+
hash = JSON.parse(val)
|
45
|
+
hash["class"].should == "QueueBus::Worker"
|
46
|
+
hash["args"].size.should == 1
|
47
|
+
JSON.parse(hash["args"].first).should == {"bus_class_proxy" => "QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Retry" do
|
4
|
+
class RetryTest1
|
5
|
+
include QueueBus::Subscriber
|
6
|
+
application :my_thing
|
7
|
+
subscribe :event_sub
|
8
|
+
def event_sub(attributes)
|
9
|
+
QueueBus::Runner1.run(attributes)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have the methods" do
|
14
|
+
::QueueBus::Worker.methods.should include(:on_failure_aaa)
|
15
|
+
::QueueBus::Worker.methods.should include(:on_failure_zzz)
|
16
|
+
end
|
17
|
+
|
18
|
+
# it "should retry failed riders"
|
19
|
+
|
20
|
+
describe "Failed Jobs" do
|
21
|
+
before(:each) do
|
22
|
+
QueueBus.enqueue_to("testing", "QueueBus::Worker", { "bus_class_proxy" => "QueueBus::Rider", "bus_rider_app_key" => "r2", "bus_rider_sub_key" => "event_name", "bus_event_type" => "event_name", "ok" => true, "bus_rider_queue" => "testing" })
|
23
|
+
|
24
|
+
@worker = Resque::Worker.new(:testing)
|
25
|
+
@worker.register_worker
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should put it in the failed jobs" do
|
29
|
+
|
30
|
+
QueueBus.dispatch("r2") do
|
31
|
+
subscribe "event_name" do |attributes|
|
32
|
+
raise "boo!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
perform_next_job @worker
|
37
|
+
Resque.info[:processed].should == 1
|
38
|
+
Resque.info[:failed].should == 1
|
39
|
+
Resque.info[:pending].should == 1 # requeued
|
40
|
+
|
41
|
+
perform_next_job @worker
|
42
|
+
Resque.info[:processed].should == 2
|
43
|
+
Resque.info[:failed].should == 2
|
44
|
+
Resque.info[:pending].should == 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'resque-bus'
|
2
|
+
require 'resque'
|
3
|
+
require 'resque/scheduler'
|
4
|
+
|
5
|
+
def reset_test_adapter
|
6
|
+
QueueBus.send(:reset)
|
7
|
+
QueueBus.adapter = QueueBus::Adapters::Resque.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def adapter_under_test_class
|
11
|
+
QueueBus::Adapters::Resque
|
12
|
+
end
|
13
|
+
|
14
|
+
def adapter_under_test_symbol
|
15
|
+
:resque
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform_next_job(worker, &block)
|
19
|
+
return unless job = worker.reserve
|
20
|
+
worker.perform(job, &block)
|
21
|
+
worker.done_working
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "adapter is set" do
|
4
|
+
it "should call it's enabled! method on init" do
|
5
|
+
QueueBus.send(:reset)
|
6
|
+
adapter_under_test_class.any_instance.should_receive(:enabled!)
|
7
|
+
instance = adapter_under_test_class.new
|
8
|
+
QueueBus.send(:reset)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be defaulting to Data from spec_helper" do
|
12
|
+
QueueBus.adapter.is_a?(adapter_under_test_class).should == true
|
13
|
+
end
|
14
|
+
end
|