queueing_rabbit 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/lib/queueing_rabbit/callbacks.rb +6 -2
- data/lib/queueing_rabbit/client/amqp.rb +0 -9
- data/lib/queueing_rabbit/client/bunny.rb +1 -6
- data/lib/queueing_rabbit/version.rb +1 -1
- data/lib/queueing_rabbit/worker.rb +16 -11
- data/queueing_rabbit.gemspec +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/queueing_rabbit/buses/abstract_bus_spec.rb +2 -2
- data/spec/unit/queueing_rabbit/callbacks_spec.rb +14 -0
- data/spec/unit/queueing_rabbit/client/amqp_spec.rb +18 -51
- data/spec/unit/queueing_rabbit/client/bunny_spec.rb +15 -15
- data/spec/unit/queueing_rabbit/extensions/retryable_spec.rb +3 -3
- data/spec/unit/queueing_rabbit/extensions/threaded_spec.rb +1 -1
- data/spec/unit/queueing_rabbit/jobs/abstract_job_spec.rb +7 -7
- data/spec/unit/queueing_rabbit/jobs/json_job_spec.rb +1 -1
- data/spec/unit/queueing_rabbit/worker_spec.rb +29 -9
- data/spec/unit/queueing_rabbit_spec.rb +39 -39
- metadata +8 -8
data/Gemfile
CHANGED
@@ -10,6 +10,10 @@ module QueueingRabbit
|
|
10
10
|
setup_callback(:consuming_done, &block)
|
11
11
|
end
|
12
12
|
|
13
|
+
def on_consumer_error(&block)
|
14
|
+
setup_callback(:consumer_error, &block)
|
15
|
+
end
|
16
|
+
|
13
17
|
def on_event_machine_start(&block)
|
14
18
|
setup_callback(:event_machine_started, &block)
|
15
19
|
end
|
@@ -20,9 +24,9 @@ module QueueingRabbit
|
|
20
24
|
@callbacks[event] << block
|
21
25
|
end
|
22
26
|
|
23
|
-
def trigger_event(event)
|
27
|
+
def trigger_event(event, *args)
|
24
28
|
if @callbacks && @callbacks[event]
|
25
|
-
@callbacks[event].each { |c| c.call }
|
29
|
+
@callbacks[event].each { |c| c.call(*args) }
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
@@ -97,16 +97,7 @@ module QueueingRabbit
|
|
97
97
|
|
98
98
|
def listen_queue(queue, options = {}, &block)
|
99
99
|
queue.subscribe(options) do |metadata, payload|
|
100
|
-
process_message(payload, metadata, &block)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def process_message(payload, metadata)
|
105
|
-
begin
|
106
100
|
yield payload, metadata
|
107
|
-
rescue => e
|
108
|
-
error "unexpected error #{e.class} occured: #{e.message}"
|
109
|
-
debug e
|
110
101
|
end
|
111
102
|
end
|
112
103
|
|
@@ -79,12 +79,7 @@ module QueueingRabbit
|
|
79
79
|
|
80
80
|
def listen_queue(queue, options = {})
|
81
81
|
queue.subscribe(options) do |delivery_info, properties, payload|
|
82
|
-
|
83
|
-
yield payload, Metadata.new(queue.channel, delivery_info, properties)
|
84
|
-
rescue => e
|
85
|
-
error "unexpected error #{e.class} occured: #{e.message}"
|
86
|
-
debug e
|
87
|
-
end
|
82
|
+
yield payload, Metadata.new(queue.channel, delivery_info, properties)
|
88
83
|
end
|
89
84
|
end
|
90
85
|
|
@@ -67,6 +67,22 @@ module QueueingRabbit
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
+
def invoke_job(job, payload, metadata)
|
71
|
+
info "performing job #{job}"
|
72
|
+
|
73
|
+
if job.respond_to?(:perform)
|
74
|
+
job.perform(payload, metadata)
|
75
|
+
elsif job <= QueueingRabbit::AbstractJob
|
76
|
+
job.new(payload, metadata).perform
|
77
|
+
else
|
78
|
+
error "don't know how to perform job #{job}"
|
79
|
+
end
|
80
|
+
rescue => e
|
81
|
+
QueueingRabbit.trigger_event(:consumer_error, e)
|
82
|
+
error "unexpected error #{e.class} occured: #{e.message}"
|
83
|
+
debug e
|
84
|
+
end
|
85
|
+
|
70
86
|
private
|
71
87
|
|
72
88
|
def validate_jobs
|
@@ -90,22 +106,11 @@ module QueueingRabbit
|
|
90
106
|
def run_job(conn, job)
|
91
107
|
QueueingRabbit.follow_job_requirements(job) do |_, _, queue|
|
92
108
|
conn.listen_queue(queue, job.listening_options) do |payload, metadata|
|
93
|
-
info "performing job #{job}"
|
94
109
|
invoke_job(job, payload, metadata)
|
95
110
|
end
|
96
111
|
end
|
97
112
|
end
|
98
113
|
|
99
|
-
def invoke_job(job, payload, metadata)
|
100
|
-
if job.respond_to?(:perform)
|
101
|
-
job.perform(payload, metadata)
|
102
|
-
elsif job <= QueueingRabbit::AbstractJob
|
103
|
-
job.new(payload, metadata).perform
|
104
|
-
else
|
105
|
-
error "don't know how to perform job #{job}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
114
|
def sync_stdio
|
110
115
|
$stdout.sync = true
|
111
116
|
$stderr.sync = true
|
data/queueing_rabbit.gemspec
CHANGED
@@ -18,8 +18,8 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.extra_rdoc_files = [ "LICENSE", "README.md" ]
|
19
19
|
gem.rdoc_options = ["--charset=UTF-8"]
|
20
20
|
|
21
|
-
gem.add_dependency "amqp", "~> 1.
|
22
|
-
gem.add_dependency "bunny", "~> 1.
|
21
|
+
gem.add_dependency "amqp", "~> 1.3.0"
|
22
|
+
gem.add_dependency "bunny", "~> 1.2.2"
|
23
23
|
gem.add_dependency "rake", ">= 0"
|
24
24
|
gem.add_dependency "json", ">= 0"
|
25
25
|
|
data/spec/spec_helper.rb
CHANGED
@@ -24,7 +24,7 @@ describe QueueingRabbit::AbstractBus do
|
|
24
24
|
|
25
25
|
describe '.demand_batch_publishing!' do
|
26
26
|
|
27
|
-
let(:exchange) {
|
27
|
+
let(:exchange) { double }
|
28
28
|
|
29
29
|
it 'assigns a shared exchange instance to a job class' do
|
30
30
|
QueueingRabbit.should_receive(:follow_bus_requirements).
|
@@ -32,7 +32,7 @@ describe QueueingRabbit::AbstractBus do
|
|
32
32
|
and_yield(nil, exchange)
|
33
33
|
subject.demand_batch_publishing!
|
34
34
|
expect(subject.shared_exchange).to eq(exchange)
|
35
|
-
expect(subject.batch_publishing?).to
|
35
|
+
expect(subject.batch_publishing?).to be true
|
36
36
|
expect(QueueingRabbit::AbstractBus.shared_exchange).to be_nil
|
37
37
|
end
|
38
38
|
|
@@ -50,4 +50,18 @@ describe QueueingRabbit::Callbacks do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
describe 'a callback with an argument' do
|
55
|
+
let(:result) { {} }
|
56
|
+
let(:callback) { Proc.new { |a| result.merge!(:answer => a) } }
|
57
|
+
|
58
|
+
before do
|
59
|
+
subject.setup_callback(:answer!, &callback)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'executes a callback with an argument' do
|
63
|
+
expect{subject.trigger_event(:answer!, 42)}.
|
64
|
+
to change{result}.to(:answer => 42)
|
65
|
+
end
|
66
|
+
end
|
53
67
|
end
|
@@ -5,7 +5,7 @@ describe QueueingRabbit::Client::AMQP do
|
|
5
5
|
include_context "StringIO logger"
|
6
6
|
include_context "No existing connections"
|
7
7
|
|
8
|
-
let(:connection) {
|
8
|
+
let(:connection) { double(:on_tcp_connection_loss => nil, :on_recovery => nil) }
|
9
9
|
|
10
10
|
before do
|
11
11
|
QueueingRabbit.stub(:amqp_uri => 'amqp://localhost:5672')
|
@@ -77,7 +77,7 @@ describe QueueingRabbit::Client::AMQP do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe '.join_event_machine_thread' do
|
80
|
-
let(:thread) {
|
80
|
+
let(:thread) { double(:join => true) }
|
81
81
|
|
82
82
|
before do
|
83
83
|
subject.instance_variable_set(:@event_machine_thread, thread)
|
@@ -102,8 +102,8 @@ describe QueueingRabbit::Client::AMQP do
|
|
102
102
|
it { should be }
|
103
103
|
|
104
104
|
describe '#define_queue' do
|
105
|
-
let(:channel) {
|
106
|
-
let(:queue) {
|
105
|
+
let(:channel) { double }
|
106
|
+
let(:queue) { double }
|
107
107
|
let(:queue_name) { "test_queue_name" }
|
108
108
|
let(:options) { {:durable => false} }
|
109
109
|
|
@@ -118,10 +118,10 @@ describe QueueingRabbit::Client::AMQP do
|
|
118
118
|
end
|
119
119
|
|
120
120
|
describe '#listen_queue' do
|
121
|
-
let(:options) {
|
122
|
-
let(:queue) {
|
123
|
-
let(:metadata) {
|
124
|
-
let(:payload) {
|
121
|
+
let(:options) { double }
|
122
|
+
let(:queue) { double }
|
123
|
+
let(:metadata) { double }
|
124
|
+
let(:payload) { double }
|
125
125
|
|
126
126
|
before do
|
127
127
|
queue.should_receive(:subscribe).with(options).
|
@@ -136,39 +136,6 @@ describe QueueingRabbit::Client::AMQP do
|
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
139
|
-
describe '#process_message' do
|
140
|
-
let(:payload) { mock }
|
141
|
-
let(:metadata) { mock }
|
142
|
-
|
143
|
-
it "yields given arguments to the block" do
|
144
|
-
client.process_message(payload, metadata) do |p, m|
|
145
|
-
p.should == payload
|
146
|
-
m.should == metadata
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
it "silences all errors risen" do
|
151
|
-
expect {
|
152
|
-
client.process_message(payload, metadata) do |_, _|
|
153
|
-
raise StandardError.new
|
154
|
-
end
|
155
|
-
}.to_not raise_error(StandardError)
|
156
|
-
end
|
157
|
-
|
158
|
-
context "logging" do
|
159
|
-
let(:error) { StandardError.new }
|
160
|
-
|
161
|
-
before do
|
162
|
-
client.should_receive(:error)
|
163
|
-
client.should_receive(:debug).with(error)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "keeps the record of all errors risen" do
|
167
|
-
client.process_message(payload, metadata) { |_, _| raise error }
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
139
|
describe '#close' do
|
173
140
|
before do
|
174
141
|
subject.should_receive(:info)
|
@@ -183,8 +150,8 @@ describe QueueingRabbit::Client::AMQP do
|
|
183
150
|
|
184
151
|
describe "#open_channel" do
|
185
152
|
let(:options) { {:use_publisher_confirms => true} }
|
186
|
-
let(:channel) {
|
187
|
-
let(:open_ok) {
|
153
|
+
let(:channel) { double }
|
154
|
+
let(:open_ok) { double }
|
188
155
|
|
189
156
|
before do
|
190
157
|
AMQP::Channel.should_receive(:new).
|
@@ -202,8 +169,8 @@ describe QueueingRabbit::Client::AMQP do
|
|
202
169
|
|
203
170
|
describe '#define_exchange' do
|
204
171
|
context 'when only channel is given' do
|
205
|
-
let(:channel) {
|
206
|
-
let(:default_exchange) {
|
172
|
+
let(:channel) { double }
|
173
|
+
let(:default_exchange) { double }
|
207
174
|
|
208
175
|
before do
|
209
176
|
channel.should_receive(:default_exchange).and_return(default_exchange)
|
@@ -215,10 +182,10 @@ describe QueueingRabbit::Client::AMQP do
|
|
215
182
|
end
|
216
183
|
|
217
184
|
context 'with arguments and type' do
|
218
|
-
let(:channel) {
|
185
|
+
let(:channel) { double }
|
219
186
|
let(:name) { 'some_exchange_name' }
|
220
187
|
let(:options) { {:type => 'direct', :durable => true} }
|
221
|
-
let(:exchange) {
|
188
|
+
let(:exchange) { double }
|
222
189
|
|
223
190
|
it 'creates an exchange of given type and options' do
|
224
191
|
channel.should_receive(:direct).with(name, :durable => true).
|
@@ -229,9 +196,9 @@ describe QueueingRabbit::Client::AMQP do
|
|
229
196
|
end
|
230
197
|
|
231
198
|
describe '#enqueue' do
|
232
|
-
let(:exchange) {
|
233
|
-
let(:payload) {
|
234
|
-
let(:options) {
|
199
|
+
let(:exchange) { double }
|
200
|
+
let(:payload) { double }
|
201
|
+
let(:options) { double }
|
235
202
|
|
236
203
|
it "publishes a new message to given exchange with given options" do
|
237
204
|
exchange.should_receive(:publish).with(payload, options)
|
@@ -250,7 +217,7 @@ describe QueueingRabbit::Client::AMQP do
|
|
250
217
|
|
251
218
|
describe '#purge_queue' do
|
252
219
|
|
253
|
-
let(:queue) {
|
220
|
+
let(:queue) { double }
|
254
221
|
|
255
222
|
it 'purges the queue and fires the provided callback when done' do
|
256
223
|
queue.should_receive(:purge).and_yield
|
@@ -4,10 +4,10 @@ describe QueueingRabbit::Client::Bunny do
|
|
4
4
|
|
5
5
|
include_context "No existing connections"
|
6
6
|
|
7
|
-
let(:connection) {
|
7
|
+
let(:connection) { double(:start => true) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
QueueingRabbit.
|
10
|
+
allow(QueueingRabbit).to receive(:amqp_uri).and_return('amqp://localhost:5672')
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'class' do
|
@@ -37,7 +37,7 @@ describe QueueingRabbit::Client::Bunny do
|
|
37
37
|
|
38
38
|
describe '#open_channel' do
|
39
39
|
let(:options) { {:use_publisher_confirms => true, :prefetch => 42} }
|
40
|
-
let(:channel) {
|
40
|
+
let(:channel) { double }
|
41
41
|
|
42
42
|
before do
|
43
43
|
connection.should_receive(:create_channel).and_return(channel)
|
@@ -53,8 +53,8 @@ describe QueueingRabbit::Client::Bunny do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe '#define_queue' do
|
56
|
-
let(:channel) {
|
57
|
-
let(:queue) {
|
56
|
+
let(:channel) { double }
|
57
|
+
let(:queue) { double }
|
58
58
|
let(:name) { 'queue_name_test' }
|
59
59
|
let(:options) { {:foo => 'bar'} }
|
60
60
|
|
@@ -75,7 +75,7 @@ describe QueueingRabbit::Client::Bunny do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
describe '#queue_size' do
|
78
|
-
let(:queue) {
|
78
|
+
let(:queue) { double }
|
79
79
|
let(:status) { {:message_count => 42} }
|
80
80
|
|
81
81
|
before do
|
@@ -89,8 +89,8 @@ describe QueueingRabbit::Client::Bunny do
|
|
89
89
|
|
90
90
|
describe '#define_exchange' do
|
91
91
|
context 'when only channel is given' do
|
92
|
-
let(:channel) {
|
93
|
-
let(:default_exchange) {
|
92
|
+
let(:channel) { double }
|
93
|
+
let(:default_exchange) { double }
|
94
94
|
|
95
95
|
before do
|
96
96
|
channel.should_receive(:default_exchange).
|
@@ -103,10 +103,10 @@ describe QueueingRabbit::Client::Bunny do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
context 'with arguments and type' do
|
106
|
-
let(:channel) {
|
106
|
+
let(:channel) { double }
|
107
107
|
let(:name) { 'some_exchange_name' }
|
108
108
|
let(:options) { {:type => 'direct', :durable => true} }
|
109
|
-
let(:exchange) {
|
109
|
+
let(:exchange) { double }
|
110
110
|
|
111
111
|
it 'creates an exchange of given type and options' do
|
112
112
|
channel.should_receive(:direct).with(name, :durable => true).
|
@@ -117,9 +117,9 @@ describe QueueingRabbit::Client::Bunny do
|
|
117
117
|
end
|
118
118
|
|
119
119
|
describe '#enqueue' do
|
120
|
-
let(:exchange) {
|
121
|
-
let(:payload) {
|
122
|
-
let(:options) {
|
120
|
+
let(:exchange) { double }
|
121
|
+
let(:payload) { double }
|
122
|
+
let(:options) { double }
|
123
123
|
|
124
124
|
it "publishes a new message to given exchange with given options" do
|
125
125
|
exchange.should_receive(:publish).with(payload, options)
|
@@ -147,7 +147,7 @@ describe QueueingRabbit::Client::Bunny do
|
|
147
147
|
|
148
148
|
describe '#purge_queue' do
|
149
149
|
|
150
|
-
let(:queue) {
|
150
|
+
let(:queue) { double }
|
151
151
|
|
152
152
|
it 'purges the queue and fires the provided callback when done' do
|
153
153
|
queue.should_receive(:purge)
|
@@ -164,7 +164,7 @@ describe QueueingRabbit::Client::Bunny do
|
|
164
164
|
client.connection.should_receive(:close)
|
165
165
|
Thread.new { sleep 1; client.next_tick { client.close } }
|
166
166
|
expect { Timeout.timeout(5) { client.begin_worker_loop } }.
|
167
|
-
not_to raise_error(Timeout::Error)
|
167
|
+
not_to raise_error { |e| expect(e).to be_a(Timeout::Error) }
|
168
168
|
end
|
169
169
|
|
170
170
|
end
|
@@ -13,9 +13,9 @@ describe QueueingRabbit::JobExtensions::Retryable do
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
}
|
16
|
-
let(:payload) {
|
16
|
+
let(:payload) { double }
|
17
17
|
let(:headers) { {'qr_retries' => 2} }
|
18
|
-
let(:metadata) {
|
18
|
+
let(:metadata) { double(:headers => headers)}
|
19
19
|
|
20
20
|
subject { test_job.new(payload, metadata) }
|
21
21
|
|
@@ -29,7 +29,7 @@ describe QueueingRabbit::JobExtensions::Retryable do
|
|
29
29
|
it 'retries with increased number of attempts' do
|
30
30
|
test_job.should_receive(:enqueue).
|
31
31
|
with(payload, :headers => {'qr_retries' => 3}).and_return(true)
|
32
|
-
subject.retry_upto(3).should
|
32
|
+
subject.retry_upto(3).should be true
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
@@ -34,7 +34,7 @@ describe QueueingRabbit::JobExtensions::Threaded, :ruby => '1.8.7' do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'new instance methods' do
|
37
|
-
subject { test_job.new(
|
37
|
+
subject { test_job.new(double, double) }
|
38
38
|
|
39
39
|
it { should respond_to(:perform_and_terminate) }
|
40
40
|
end
|
@@ -36,7 +36,7 @@ describe QueueingRabbit::AbstractJob do
|
|
36
36
|
its(:publishing_defaults) { should include(:routing_key => 'test_queue') }
|
37
37
|
|
38
38
|
describe ".queue_size" do
|
39
|
-
let(:size) {
|
39
|
+
let(:size) { double }
|
40
40
|
|
41
41
|
before do
|
42
42
|
QueueingRabbit.should_receive(:queue_size).with(subject).and_return(size)
|
@@ -47,7 +47,7 @@ describe QueueingRabbit::AbstractJob do
|
|
47
47
|
|
48
48
|
describe '.demand_batch_publishing!' do
|
49
49
|
|
50
|
-
let(:exchange) {
|
50
|
+
let(:exchange) { double }
|
51
51
|
|
52
52
|
it 'assigns a shared exchange instance to a job class' do
|
53
53
|
QueueingRabbit.should_receive(:follow_job_requirements).
|
@@ -55,14 +55,14 @@ describe QueueingRabbit::AbstractJob do
|
|
55
55
|
and_yield(nil, exchange, nil)
|
56
56
|
subject.demand_batch_publishing!
|
57
57
|
expect(subject.shared_exchange).to eq(exchange)
|
58
|
-
expect(subject.batch_publishing?).to
|
58
|
+
expect(subject.batch_publishing?).to be true
|
59
59
|
expect(QueueingRabbit::AbstractJob.shared_exchange).to be_nil
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
63
63
|
|
64
64
|
describe '.enqueue' do
|
65
|
-
let(:payload) {
|
65
|
+
let(:payload) { double }
|
66
66
|
let(:options) { {:persistent => true} }
|
67
67
|
let(:result_options) { options.merge(job_class.publishing_defaults) }
|
68
68
|
|
@@ -74,9 +74,9 @@ describe QueueingRabbit::AbstractJob do
|
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'instance methods' do
|
77
|
-
let(:payload) {
|
78
|
-
let(:headers) {
|
79
|
-
let(:metadata) {
|
77
|
+
let(:payload) { double }
|
78
|
+
let(:headers) { double }
|
79
|
+
let(:metadata) { double(:headers => headers) }
|
80
80
|
|
81
81
|
subject { job_class.new(payload, metadata) }
|
82
82
|
|
@@ -60,10 +60,10 @@ describe QueueingRabbit::Worker do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
context 'instance methods' do
|
63
|
-
let(:connection) {
|
64
|
-
let(:queue) {
|
65
|
-
let(:payload) {
|
66
|
-
let(:metadata) {
|
63
|
+
let(:connection) { double }
|
64
|
+
let(:queue) { double }
|
65
|
+
let(:payload) { double }
|
66
|
+
let(:metadata) { double }
|
67
67
|
|
68
68
|
subject { worker }
|
69
69
|
|
@@ -82,7 +82,7 @@ describe QueueingRabbit::Worker do
|
|
82
82
|
class_based_job.should_receive(:perform).with(payload, metadata)
|
83
83
|
instance_based_job.should_receive(:new).
|
84
84
|
with(payload, metadata).
|
85
|
-
and_return(
|
85
|
+
and_return(double(:perform => nil))
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'listens to queues specified by jobs' do
|
@@ -103,8 +103,8 @@ describe QueueingRabbit::Worker do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
describe "#use_pidfile" do
|
106
|
-
let(:file_name) {
|
107
|
-
let(:file) {
|
106
|
+
let(:file_name) { double }
|
107
|
+
let(:file) { double }
|
108
108
|
|
109
109
|
context 'given pidfile is already in use' do
|
110
110
|
|
@@ -149,7 +149,7 @@ describe QueueingRabbit::Worker do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
describe "#remove_pidfile" do
|
152
|
-
let(:file_name) {
|
152
|
+
let(:file_name) { double }
|
153
153
|
|
154
154
|
before do
|
155
155
|
subject.instance_variable_set(:@pidfile, file_name)
|
@@ -162,13 +162,33 @@ describe QueueingRabbit::Worker do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
|
+
describe '#invoke_job' do
|
166
|
+
let(:payload) { double }
|
167
|
+
let(:metadata) { double }
|
168
|
+
|
169
|
+
context 'when an exception occurs' do
|
170
|
+
|
171
|
+
let(:job) { double }
|
172
|
+
let(:error) { StandardError.new }
|
173
|
+
|
174
|
+
it 'silences errors and reports them via a global callback' do
|
175
|
+
expect(job).to receive(:perform).and_raise(error)
|
176
|
+
expect(QueueingRabbit).
|
177
|
+
to receive(:trigger_event).with(:consumer_error, error)
|
178
|
+
subject.invoke_job(job, payload, metadata)
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
165
185
|
describe "#pid" do
|
166
186
|
its(:pid) { should == Process.pid }
|
167
187
|
end
|
168
188
|
|
169
189
|
describe '#stop' do
|
170
190
|
|
171
|
-
let(:file_name) {
|
191
|
+
let(:file_name) { double }
|
172
192
|
|
173
193
|
before do
|
174
194
|
subject.instance_variable_set(:@pidfile, file_name)
|
@@ -4,24 +4,24 @@ describe QueueingRabbit do
|
|
4
4
|
include_context "No existing connections"
|
5
5
|
include_context "StringIO logger"
|
6
6
|
|
7
|
-
let(:connection) {
|
8
|
-
let(:queue_name) {
|
7
|
+
let(:connection) { double }
|
8
|
+
let(:queue_name) { double }
|
9
9
|
let(:queue_options) { {:durable => true} }
|
10
|
-
let(:channel) {
|
10
|
+
let(:channel) { double }
|
11
11
|
let(:channel_options) { {:prefetch => 1, :auto_recovery => true} }
|
12
|
-
let(:exchange_name) {
|
12
|
+
let(:exchange_name) { double }
|
13
13
|
let(:exchange_options) { {:type => :direct, :durable => true} }
|
14
14
|
let(:binding_declaration_1) { {:routing_key => 'routing_key'} }
|
15
15
|
let(:binding_declaration_2) { {:routing_key => 'routing_key2'} }
|
16
16
|
let(:job) {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
double(:queue_name => queue_name,
|
18
|
+
:queue_options => queue_options,
|
19
|
+
:channel_options => channel_options,
|
20
|
+
:exchange_name => exchange_name,
|
21
|
+
:exchange_options => exchange_options,
|
22
|
+
:binding_declarations => [binding_declaration_1,
|
23
|
+
binding_declaration_2],
|
24
|
+
:bind_queue? => true)
|
25
25
|
}
|
26
26
|
|
27
27
|
it { should respond_to(:logger) }
|
@@ -42,10 +42,10 @@ describe QueueingRabbit do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe ".enqueue" do
|
45
|
-
let(:payload) {
|
46
|
-
let(:options) {
|
47
|
-
let(:exchange) {
|
48
|
-
let(:channel) {
|
45
|
+
let(:payload) { double(:to_s => 'payload') }
|
46
|
+
let(:options) { double }
|
47
|
+
let(:exchange) { double }
|
48
|
+
let(:channel) { double }
|
49
49
|
|
50
50
|
before do
|
51
51
|
subject.instance_variable_set(:@connection, connection)
|
@@ -57,22 +57,22 @@ describe QueueingRabbit do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'returns true when a message was enqueued successfully' do
|
60
|
-
subject.enqueue(job, payload, options).should
|
60
|
+
subject.enqueue(job, payload, options).should be true
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'keeps the record of enqueued job at info level' do
|
64
64
|
subject.should_receive(:info).and_return(nil)
|
65
|
-
subject.enqueue(job, payload, options).should
|
65
|
+
subject.enqueue(job, payload, options).should be true
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
describe '.publish' do
|
70
70
|
|
71
71
|
let(:bus) { QueueingRabbit::AbstractBus }
|
72
|
-
let(:payload) {
|
73
|
-
let(:options) {
|
74
|
-
let(:exchange) {
|
75
|
-
let(:channel) {
|
72
|
+
let(:payload) { double(:to_s => 'payload') }
|
73
|
+
let(:options) { double }
|
74
|
+
let(:exchange) { double }
|
75
|
+
let(:channel) { double }
|
76
76
|
|
77
77
|
it 'publishes payload to a given bus with options' do
|
78
78
|
subject.instance_variable_set(:@connection, connection)
|
@@ -81,21 +81,21 @@ describe QueueingRabbit do
|
|
81
81
|
and_yield(channel, exchange)
|
82
82
|
connection.should_receive(:publish).with(exchange, payload, options)
|
83
83
|
channel.should_receive(:close)
|
84
|
-
subject.publish(bus, payload, options).should
|
84
|
+
subject.publish(bus, payload, options).should be true
|
85
85
|
end
|
86
86
|
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '.publish_to_exchange' do
|
90
90
|
|
91
|
-
let(:exchange) {
|
92
|
-
let(:payload) {
|
93
|
-
let(:options) {
|
91
|
+
let(:exchange) { double }
|
92
|
+
let(:payload) { double }
|
93
|
+
let(:options) { double }
|
94
94
|
|
95
95
|
it 'publishes payload to a given exchange with options' do
|
96
96
|
subject.instance_variable_set(:@connection, connection)
|
97
97
|
connection.should_receive(:publish).with(exchange, payload, options)
|
98
|
-
subject.publish_to_exchange(exchange, payload, options).should
|
98
|
+
subject.publish_to_exchange(exchange, payload, options).should be true
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
@@ -114,9 +114,9 @@ describe QueueingRabbit do
|
|
114
114
|
end
|
115
115
|
|
116
116
|
describe '.follow_job_requirements' do
|
117
|
-
let(:channel) {
|
118
|
-
let(:exchange) {
|
119
|
-
let(:queue) {
|
117
|
+
let(:channel) { double }
|
118
|
+
let(:exchange) { double }
|
119
|
+
let(:queue) { double }
|
120
120
|
|
121
121
|
before do
|
122
122
|
subject.instance_variable_set(:@connection, connection)
|
@@ -144,12 +144,12 @@ describe QueueingRabbit do
|
|
144
144
|
end
|
145
145
|
|
146
146
|
describe '.follow_bus_requirements' do
|
147
|
-
let(:channel) {
|
148
|
-
let(:exchange) {
|
147
|
+
let(:channel) { double }
|
148
|
+
let(:exchange) { double }
|
149
149
|
let(:bus) {
|
150
|
-
|
151
|
-
|
152
|
-
|
150
|
+
double(:channel_options => channel_options,
|
151
|
+
:exchange_name => exchange_name,
|
152
|
+
:exchange_options => exchange_options)
|
153
153
|
}
|
154
154
|
|
155
155
|
before do
|
@@ -171,8 +171,8 @@ describe QueueingRabbit do
|
|
171
171
|
end
|
172
172
|
|
173
173
|
describe ".queue_size" do
|
174
|
-
let(:size) {
|
175
|
-
let(:queue) {
|
174
|
+
let(:size) { double }
|
175
|
+
let(:queue) { double }
|
176
176
|
|
177
177
|
before do
|
178
178
|
subject.instance_variable_set(:@connection, connection)
|
@@ -191,7 +191,7 @@ describe QueueingRabbit do
|
|
191
191
|
end
|
192
192
|
|
193
193
|
describe ".purge_queue" do
|
194
|
-
let(:queue) {
|
194
|
+
let(:queue) { double }
|
195
195
|
|
196
196
|
before do
|
197
197
|
subject.instance_variable_set(:@connection, connection)
|
@@ -205,7 +205,7 @@ describe QueueingRabbit do
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it 'purges messages from the queue' do
|
208
|
-
subject.purge_queue(job).should
|
208
|
+
subject.purge_queue(job).should be true
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queueing_rabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
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: 2014-
|
12
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amqp
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: 1.3.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: bunny
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.
|
37
|
+
version: 1.2.2
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
45
|
+
version: 1.2.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rake
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -171,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: '0'
|
172
172
|
segments:
|
173
173
|
- 0
|
174
|
-
hash:
|
174
|
+
hash: 2464755371986051547
|
175
175
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
176
|
none: false
|
177
177
|
requirements:
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
segments:
|
182
182
|
- 0
|
183
|
-
hash:
|
183
|
+
hash: 2464755371986051547
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
186
|
rubygems_version: 1.8.23
|