queueing_rabbit 0.6.0 → 0.6.1
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +0 -2
- data/lib/queueing_rabbit/client/bunny.rb +1 -1
- data/lib/queueing_rabbit/misc/mutex_pool.rb +34 -0
- data/lib/queueing_rabbit/tasks.rb +2 -1
- data/lib/queueing_rabbit/version.rb +1 -1
- data/lib/queueing_rabbit/worker.rb +29 -56
- data/queueing_rabbit.gemspec +1 -1
- data/spec/integration/asynchronous_publishing_and_consuming_spec.rb +1 -1
- data/spec/integration/asynchronous_publishing_and_consuming_with_retries_spec.rb +1 -1
- data/spec/integration/binary_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb +1 -1
- data/spec/integration/direct_exchange_asynchronous_publishing_and_consuming_spec.rb +1 -1
- data/spec/integration/jobs/json_threaded_print_line_job.rb +1 -1
- data/spec/integration/json_job_asynchronous_publishing_and_consuming_spec.rb +1 -1
- data/spec/integration/json_job_synchronous_publishing_and_consuming_spec.rb +1 -1
- data/spec/integration/json_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb +1 -1
- data/spec/integration/persistent_asynchronous_publishing_and_consuming_spec.rb +2 -2
- data/spec/integration/synchronous_publishing_and_asynchronous_consuming_spec.rb +1 -1
- data/spec/integration/synchronous_publishing_and_consuming_spec.rb +1 -1
- data/spec/integration/synchronous_publishing_and_threaded_consuming_spec.rb +1 -1
- data/spec/integration/worker_termination_spec.rb +19 -9
- data/spec/unit/queueing_rabbit/misc/mutex_pool_spec.rb +41 -0
- data/spec/unit/queueing_rabbit/worker_spec.rb +22 -12
- metadata +33 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 502133a7d304d61ca0e0f5953fe785f8bd7678e6
|
4
|
+
data.tar.gz: c7256fabf7bbcf715c13d16e82a1a6f2c0a20d91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e38c0f5f4101190d5a168743288b6b3d14e6786fccdf9ab1adfea2d1bf0509731d1116f3692a63183747883f1cf1b315f30bda03e919fd59f4382149d141869e
|
7
|
+
data.tar.gz: f89348e12cfbc688e9bc5357f2398c2c576e5feae76c0ca764e61454686c9f3a24bde9dcd5ac2fa01b3ce47cfb1f8a319266911b2977faa0d8ff28ec2a27eb1c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -43,7 +43,7 @@ module QueueingRabbit
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def open_channel(options = {})
|
46
|
-
ch = connection.create_channel
|
46
|
+
ch = connection.create_channel(nil, options[:consumer_pool_size])
|
47
47
|
ch.prefetch(options[:prefetch]) if options[:prefetch]
|
48
48
|
ch.confirm_select if options[:use_publisher_confirms]
|
49
49
|
yield ch, nil
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class MutexPool
|
2
|
+
attr_reader :size
|
3
|
+
|
4
|
+
def initialize(size = 1)
|
5
|
+
@pool = Queue.new
|
6
|
+
@size = size
|
7
|
+
@pop_mutex = Mutex.new
|
8
|
+
@lock_mutex = Mutex.new
|
9
|
+
@locked_pool = []
|
10
|
+
@size.times { @pool << Mutex.new }
|
11
|
+
end
|
12
|
+
|
13
|
+
def synchronize(&block)
|
14
|
+
mutex = @pop_mutex.synchronize { @pool.pop }
|
15
|
+
mutex.synchronize(&block)
|
16
|
+
ensure
|
17
|
+
@pool << mutex if mutex
|
18
|
+
end
|
19
|
+
|
20
|
+
def lock
|
21
|
+
@lock_mutex.lock
|
22
|
+
@pop_mutex.lock
|
23
|
+
@locked_pool = @size.times.map { |i| @pool.pop }
|
24
|
+
end
|
25
|
+
|
26
|
+
def unlock
|
27
|
+
raise ThreadError, 'The pool is not locked' unless @lock_mutex.locked?
|
28
|
+
@locked_pool.each { |m| @pool << m }
|
29
|
+
@locked_pool = []
|
30
|
+
@pop_mutex.unlock
|
31
|
+
@lock_mutex.unlock
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -9,9 +9,10 @@ namespace :queueing_rabbit do
|
|
9
9
|
require 'queueing_rabbit'
|
10
10
|
|
11
11
|
jobs = (ENV['JOBS'] || ENV['JOB']).to_s.split(',')
|
12
|
+
concurrency = ENV['CONCURRENCY'] && ENV['CONCURRENCY'].to_i
|
12
13
|
|
13
14
|
begin
|
14
|
-
worker = QueueingRabbit::Worker.new(
|
15
|
+
worker = QueueingRabbit::Worker.new(jobs, concurrency)
|
15
16
|
rescue QueueingRabbit::JobNotPresentError, QueueingRabbit::JobNotFoundError
|
16
17
|
abort "set JOB env var, e.g. $ JOB=ExportDataJob,CompressFileJob " \
|
17
18
|
"rake queueing_rabbit:work"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "queueing_rabbit/misc/mutex_pool"
|
2
2
|
|
3
3
|
module QueueingRabbit
|
4
4
|
class Worker
|
@@ -7,54 +7,28 @@ module QueueingRabbit
|
|
7
7
|
|
8
8
|
include QueueingRabbit::Logging
|
9
9
|
|
10
|
-
|
10
|
+
attr_reader :jobs, :concurrency, :mutex_pool
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
|
14
|
-
|
15
|
-
@
|
16
|
-
@messages = {}
|
17
|
-
@channels = []
|
12
|
+
def initialize(jobs, concurrency = nil)
|
13
|
+
@jobs = jobs.map { |job| job.to_s.strip }.reject { |job| job.empty? }
|
14
|
+
@concurrency = concurrency || @jobs.count
|
15
|
+
@mutex_pool = ::MutexPool.new(@concurrency)
|
18
16
|
|
19
17
|
sync_stdio
|
20
18
|
validate_jobs
|
21
19
|
constantize_jobs
|
22
20
|
end
|
23
21
|
|
24
|
-
def checked_messages_count
|
25
|
-
@messages_lock.synchronize do
|
26
|
-
@messages.count
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def checkin_message(delivery_tag)
|
31
|
-
return unless @working
|
32
|
-
|
33
|
-
@messages_lock.synchronize do
|
34
|
-
@messages[delivery_tag] = true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def checkout_message(delivery_tag)
|
39
|
-
@messages_lock.synchronize do
|
40
|
-
@messages.delete(delivery_tag)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
22
|
def working?
|
45
23
|
@working
|
46
24
|
end
|
47
25
|
|
48
26
|
def work
|
49
27
|
return if working?
|
50
|
-
|
51
28
|
@working = true
|
52
|
-
@channels = []
|
53
29
|
|
54
30
|
QueueingRabbit.trigger_event(:worker_ready)
|
55
|
-
|
56
31
|
jobs.each { |job| run_job(QueueingRabbit.connection, job) }
|
57
|
-
|
58
32
|
QueueingRabbit.trigger_event(:consuming_started)
|
59
33
|
end
|
60
34
|
|
@@ -62,9 +36,7 @@ module QueueingRabbit
|
|
62
36
|
return if working?
|
63
37
|
|
64
38
|
trap_signals
|
65
|
-
|
66
39
|
info "starting a new queueing_rabbit worker #{self}"
|
67
|
-
|
68
40
|
QueueingRabbit.begin_worker_loop { work }
|
69
41
|
end
|
70
42
|
|
@@ -91,15 +63,26 @@ module QueueingRabbit
|
|
91
63
|
end
|
92
64
|
|
93
65
|
def to_s
|
94
|
-
"PID=#{pid}, JOBS=#{jobs.join(',')}"
|
66
|
+
"PID=#{pid}, JOBS=#{jobs.join(',')} CONCURRENCY=#{@concurrency}"
|
95
67
|
end
|
96
68
|
|
97
|
-
def stop(connection = QueueingRabbit.connection)
|
69
|
+
def stop(connection = QueueingRabbit.connection, graceful = false)
|
98
70
|
connection.next_tick do
|
99
|
-
|
100
|
-
|
101
|
-
|
71
|
+
begin
|
72
|
+
@working = false
|
73
|
+
if graceful
|
74
|
+
Timeout.timeout(QueueingRabbit.jobs_wait_timeout) { @mutex_pool.lock }
|
75
|
+
QueueingRabbit.trigger_event(:consuming_done)
|
102
76
|
info "gracefully shutting down the worker #{self}"
|
77
|
+
end
|
78
|
+
rescue Timeout::Error
|
79
|
+
error "a timeout (> #{QueueingRabbit.jobs_wait_timeout}s) when trying to gracefully shut down the worker " \
|
80
|
+
"#{self}"
|
81
|
+
rescue => e
|
82
|
+
error "a #{e.class} error occurred when trying to shut down the worker #{self}"
|
83
|
+
debug e
|
84
|
+
ensure
|
85
|
+
connection.close do
|
103
86
|
remove_pidfile
|
104
87
|
end
|
105
88
|
end
|
@@ -124,24 +107,15 @@ module QueueingRabbit
|
|
124
107
|
|
125
108
|
private
|
126
109
|
|
127
|
-
def close_channels(connection = QueueingRabbit.connection)
|
128
|
-
connection.wait_while_for(Proc.new { checked_messages_count > 0 },
|
129
|
-
QueueingRabbit.jobs_wait_timeout) do
|
130
|
-
@channels.each(&:close)
|
131
|
-
QueueingRabbit.trigger_event(:consuming_done)
|
132
|
-
yield
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
110
|
def validate_jobs
|
137
|
-
if jobs.nil? || jobs.empty?
|
111
|
+
if @jobs.nil? || @jobs.empty?
|
138
112
|
fatal "no jobs specified to work on."
|
139
113
|
raise JobNotPresentError.new("No jobs specified to work on.")
|
140
114
|
end
|
141
115
|
end
|
142
116
|
|
143
117
|
def constantize_jobs
|
144
|
-
|
118
|
+
@jobs = @jobs.map do |job|
|
145
119
|
begin
|
146
120
|
Kernel.const_get(job)
|
147
121
|
rescue NameError
|
@@ -152,12 +126,10 @@ module QueueingRabbit
|
|
152
126
|
end
|
153
127
|
|
154
128
|
def run_job(conn, job)
|
155
|
-
QueueingRabbit.follow_job_requirements(job) do |
|
156
|
-
@channels << ch
|
129
|
+
QueueingRabbit.follow_job_requirements(job) do |_, _, queue|
|
157
130
|
conn.listen_queue(queue, job.listening_options) do |payload, metadata|
|
158
|
-
|
131
|
+
@mutex_pool.synchronize do
|
159
132
|
invoke_job(job, payload, metadata)
|
160
|
-
checkout_message(metadata.object_id)
|
161
133
|
end
|
162
134
|
end
|
163
135
|
end
|
@@ -170,8 +142,9 @@ module QueueingRabbit
|
|
170
142
|
|
171
143
|
def trap_signals
|
172
144
|
connection = QueueingRabbit.connection
|
173
|
-
Signal.trap(
|
174
|
-
Signal.trap(
|
145
|
+
Signal.trap('QUIT') { stop(connection, true) }
|
146
|
+
Signal.trap('TERM') { stop(connection) }
|
147
|
+
Signal.trap('INT') { stop(connection) }
|
175
148
|
end
|
176
149
|
|
177
150
|
def cleanup_pidfile
|
data/queueing_rabbit.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.rdoc_options = ["--charset=UTF-8"]
|
20
20
|
|
21
21
|
gem.add_dependency "amqp", "~> 1.3.0"
|
22
|
-
gem.add_dependency "bunny", "~> 1.
|
22
|
+
gem.add_dependency "bunny", "~> 1.6.3"
|
23
23
|
gem.add_dependency "rake", ">= 0"
|
24
24
|
gem.add_dependency "json", ">= 0"
|
25
25
|
|
@@ -14,7 +14,7 @@ describe "Asynchronous publishing and consuming example" do
|
|
14
14
|
let(:connection) { QueueingRabbit.connection }
|
15
15
|
let(:job) { PrintLineJob }
|
16
16
|
let(:io) { StringIO.new }
|
17
|
-
let(:worker) { QueueingRabbit::Worker.new(job.to_s) }
|
17
|
+
let(:worker) { QueueingRabbit::Worker.new([job.to_s]) }
|
18
18
|
|
19
19
|
before(:each) do
|
20
20
|
QueueingRabbit.drop_connection
|
@@ -33,7 +33,7 @@ describe "Asynchronous publishing and consuming with retries" do
|
|
33
33
|
}
|
34
34
|
let(:job_name) { 'RetryablePrintLineJob' }
|
35
35
|
let(:io) { StringIO.new }
|
36
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
36
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
37
37
|
|
38
38
|
before(:each) do
|
39
39
|
QueueingRabbit.drop_connection
|
@@ -12,7 +12,7 @@ describe 'Binary synchronous publishing via bus and asynchronous consuming via j
|
|
12
12
|
end
|
13
13
|
}
|
14
14
|
let(:job) { PrintLineJob }
|
15
|
-
let(:worker) { QueueingRabbit::Worker.new(job.to_s) }
|
15
|
+
let(:worker) { QueueingRabbit::Worker.new([job.to_s]) }
|
16
16
|
let(:line) { "Hello, world!" }
|
17
17
|
let(:io) { StringIO.new }
|
18
18
|
|
@@ -21,7 +21,7 @@ describe "Asynchronous publishing and consuming using direct exchange" do
|
|
21
21
|
}
|
22
22
|
let(:job_name) { 'PrintLineDirectExchangeJob' }
|
23
23
|
let(:io) { StringIO.new }
|
24
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
24
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
25
25
|
|
26
26
|
before do
|
27
27
|
stub_const(job_name, job)
|
@@ -26,7 +26,7 @@ describe "Asynchronous publishing and consuming with JSON serialization" do
|
|
26
26
|
}
|
27
27
|
let(:job_name) { 'PrintLineFromJSONJob' }
|
28
28
|
let(:io) { StringIO.new }
|
29
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
29
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
30
30
|
|
31
31
|
before do
|
32
32
|
stub_const(job_name, job)
|
@@ -20,7 +20,7 @@ describe "Synchronous publishing and consuming with JSON serialization" do
|
|
20
20
|
}
|
21
21
|
let(:job_name) { 'PrintLineFromJSONJob' }
|
22
22
|
let(:io) { StringIO.new }
|
23
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
23
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
24
24
|
|
25
25
|
before do
|
26
26
|
job.io = io
|
data/spec/integration/json_synchronous_publishing_via_bus_and_asynchronous_consuming_via_job_spec.rb
CHANGED
@@ -25,7 +25,7 @@ describe 'JSON synchronous publishing via bus and asynchronous consuming via job
|
|
25
25
|
end
|
26
26
|
}
|
27
27
|
let(:job_name) { 'PrintLineJob' }
|
28
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
28
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
29
29
|
let(:line) { "Hello, world!" }
|
30
30
|
let(:io) { StringIO.new }
|
31
31
|
|
@@ -15,7 +15,7 @@ describe "Persistent asynchronous publishing and consuming" do
|
|
15
15
|
let(:job) {
|
16
16
|
Class.new(PrintLineJob) do
|
17
17
|
queue 'persistent_print_line_job'
|
18
|
-
listen :
|
18
|
+
listen :manual_ack => true
|
19
19
|
publish_with :persistent => true
|
20
20
|
channel :use_publisher_confirms => true
|
21
21
|
|
@@ -27,7 +27,7 @@ describe "Persistent asynchronous publishing and consuming" do
|
|
27
27
|
}
|
28
28
|
let(:job_name) { 'PrintLineWithAcknowledgmentsJob' }
|
29
29
|
let(:io) { StringIO.new }
|
30
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
30
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
31
31
|
|
32
32
|
before(:each) do
|
33
33
|
QueueingRabbit.drop_connection
|
@@ -13,7 +13,7 @@ describe "Synchronous publishing and asynchronous consuming example" do
|
|
13
13
|
|
14
14
|
context "when a message is published synchronously and being consumed " \
|
15
15
|
"asynchornously" do
|
16
|
-
let(:worker) { QueueingRabbit::Worker.new(job.to_s) }
|
16
|
+
let(:worker) { QueueingRabbit::Worker.new([job.to_s]) }
|
17
17
|
let(:io) { StringIO.new }
|
18
18
|
|
19
19
|
before do
|
@@ -10,7 +10,7 @@ describe "Synchronous publishing and asynchronous consuming example" do
|
|
10
10
|
|
11
11
|
context "when a message is published and consumed synchronously" do
|
12
12
|
|
13
|
-
let(:worker) { QueueingRabbit::Worker.new(job.to_s) }
|
13
|
+
let(:worker) { QueueingRabbit::Worker.new([job.to_s]) }
|
14
14
|
let(:io) { StringIO.new }
|
15
15
|
|
16
16
|
before do
|
@@ -11,7 +11,7 @@ describe "Synchronous publishing and threaded consuming", :ruby => '1.8.7' do
|
|
11
11
|
let(:job) { JSONThreadedPrintLineJob }
|
12
12
|
let(:job_name) { 'JSONThreadedPrintLineJob' }
|
13
13
|
let(:io) { StringIO.new }
|
14
|
-
let(:worker) { QueueingRabbit::Worker.new(job_name) }
|
14
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
15
15
|
|
16
16
|
before do
|
17
17
|
QueueingRabbit.purge_queue(job)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Terminating a worker' do
|
4
|
-
|
5
4
|
include_context 'Auto-disconnect'
|
6
5
|
include_context 'StringIO logger'
|
7
6
|
|
@@ -10,7 +9,7 @@ describe 'Terminating a worker' do
|
|
10
9
|
let(:job) {
|
11
10
|
Class.new(QueueingRabbit::AbstractJob) {
|
12
11
|
queue 'sleep_and_ack'
|
13
|
-
listen :
|
12
|
+
listen :manual_ack => true
|
14
13
|
|
15
14
|
def self.complete!
|
16
15
|
@complete = true
|
@@ -27,19 +26,30 @@ describe 'Terminating a worker' do
|
|
27
26
|
end
|
28
27
|
}
|
29
28
|
}
|
29
|
+
let(:worker) { QueueingRabbit::Worker.new([job_name]) }
|
30
30
|
|
31
31
|
before do
|
32
32
|
QueueingRabbit.purge_queue(job)
|
33
33
|
stub_const(job_name, job)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
context 'when gracefully shut down' do
|
37
|
+
it 'waits for currently running consumers' do
|
38
|
+
worker.work
|
39
|
+
job.enqueue('')
|
40
|
+
sleep 1
|
41
|
+
worker.stop(QueueingRabbit.connection, true)
|
42
|
+
expect(job).to be_complete
|
43
|
+
end
|
43
44
|
end
|
44
45
|
|
46
|
+
context 'when shut down immediately' do
|
47
|
+
it 'terminates right away' do
|
48
|
+
worker.work
|
49
|
+
job.enqueue('')
|
50
|
+
sleep 1
|
51
|
+
worker.stop
|
52
|
+
expect(job).to_not be_complete
|
53
|
+
end
|
54
|
+
end
|
45
55
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MutexPool do
|
4
|
+
it 'can be created with a size' do
|
5
|
+
expect(MutexPool.new(5)).to be_a(MutexPool)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'can be created without a size and will have size of 1' do
|
9
|
+
pool = MutexPool.new
|
10
|
+
expect(pool).to be_a(MutexPool)
|
11
|
+
expect(pool.size).to eq 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'allows for up to n locks to be allocated' do
|
15
|
+
pool = MutexPool.new(3)
|
16
|
+
expect(pool.synchronize do
|
17
|
+
pool.synchronize do
|
18
|
+
pool.synchronize do
|
19
|
+
1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end).to eq 1
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can be locked so no one can obtain locks' do
|
26
|
+
pool = MutexPool.new(2)
|
27
|
+
pool.lock
|
28
|
+
thread = Thread.new { pool.synchronize { true } }
|
29
|
+
sleep 0.1
|
30
|
+
expect(thread.status).to eq 'sleep'
|
31
|
+
thread.exit
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can be unlocked allowing consumers to obtain locks again' do
|
35
|
+
pool = MutexPool.new(2)
|
36
|
+
pool.lock
|
37
|
+
thread = Thread.new { pool.synchronize { true } }
|
38
|
+
sleep 0.1
|
39
|
+
expect{pool.unlock; sleep 0.1}.to change{thread.status}.from('sleep').to(false)
|
40
|
+
end
|
41
|
+
end
|
@@ -12,7 +12,7 @@ describe QueueingRabbit::Worker do
|
|
12
12
|
let(:instance_based_job) { Class.new(QueueingRabbit::AbstractJob) }
|
13
13
|
let(:creation) {
|
14
14
|
Proc.new do
|
15
|
-
QueueingRabbit::Worker.new('QueueingRabbitClassJob', QueueingRabbitInstanceJob)
|
15
|
+
QueueingRabbit::Worker.new(['QueueingRabbitClassJob', QueueingRabbitInstanceJob])
|
16
16
|
end
|
17
17
|
}
|
18
18
|
let(:worker) { creation.call }
|
@@ -33,7 +33,7 @@ describe QueueingRabbit::Worker do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'raises JobNotPresentError' do
|
36
|
-
expect { subject.new() }.
|
36
|
+
expect { subject.new([]) }.
|
37
37
|
to raise_error(QueueingRabbit::JobNotPresentError)
|
38
38
|
end
|
39
39
|
end
|
@@ -46,7 +46,7 @@ describe QueueingRabbit::Worker do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'raises JobNotFoundError' do
|
49
|
-
expect { subject.new(nonexistent_class_name) }.
|
49
|
+
expect { subject.new([nonexistent_class_name]) }.
|
50
50
|
to raise_error(QueueingRabbit::JobNotFoundError)
|
51
51
|
end
|
52
52
|
end
|
@@ -187,7 +187,6 @@ describe QueueingRabbit::Worker do
|
|
187
187
|
end
|
188
188
|
|
189
189
|
describe '#stop' do
|
190
|
-
|
191
190
|
let(:file_name) { double }
|
192
191
|
|
193
192
|
before do
|
@@ -195,16 +194,27 @@ describe QueueingRabbit::Worker do
|
|
195
194
|
QueueingRabbit.stub(:connection).and_return(connection)
|
196
195
|
end
|
197
196
|
|
198
|
-
|
199
|
-
connection
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
197
|
+
context 'when stopped gracefully' do
|
198
|
+
it 'closes the connection, removes the pidfile, waits for jobs to finish and reports the event' do
|
199
|
+
connection.should_receive(:next_tick).and_yield
|
200
|
+
connection.should_receive(:close).and_yield
|
201
|
+
worker.mutex_pool.should_receive(:lock)
|
202
|
+
QueueingRabbit.should_receive(:trigger_event).with(:consuming_done)
|
203
|
+
File.stub(:exists?).with(file_name).and_return(true)
|
204
|
+
File.should_receive(:delete).with(file_name)
|
205
|
+
subject.stop(QueueingRabbit.connection, true)
|
206
|
+
end
|
206
207
|
end
|
207
208
|
|
209
|
+
context 'when stopped immediately' do
|
210
|
+
it 'closes the connection and removes the pidfile' do
|
211
|
+
connection.should_receive(:next_tick).and_yield
|
212
|
+
connection.should_receive(:close).and_yield
|
213
|
+
File.stub(:exists?).with(file_name).and_return(true)
|
214
|
+
File.should_receive(:delete).with(file_name)
|
215
|
+
subject.stop
|
216
|
+
end
|
217
|
+
end
|
208
218
|
end
|
209
219
|
|
210
220
|
end
|
metadata
CHANGED
@@ -1,86 +1,81 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queueing_rabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Artem Chistyakov
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: amqp
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.3.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 1.3.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bunny
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: 1.
|
33
|
+
version: 1.6.3
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.
|
40
|
+
version: 1.6.3
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: json
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
|
-
description:
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
69
|
+
description: |2
|
70
|
+
QueueingRabbit is a Ruby library providing a flexible DSL to interact with a
|
71
|
+
RabbitMQ server.
|
72
|
+
|
73
|
+
Any Ruby class or Module can be transformed into QueueingRabbit's background
|
74
|
+
job by including QueueingRabbit::Job module. It is also possible to inherit
|
75
|
+
your class from QueueingRabbit::AbstractJob abstract class.
|
76
|
+
|
77
|
+
The library is bundled with a Rake task to start a worker processing a list
|
78
|
+
of specified jobs.
|
84
79
|
email:
|
85
80
|
- chistyakov.artem@gmail.com
|
86
81
|
executables: []
|
@@ -89,8 +84,8 @@ extra_rdoc_files:
|
|
89
84
|
- LICENSE
|
90
85
|
- README.md
|
91
86
|
files:
|
92
|
-
- .gitignore
|
93
|
-
- .travis.yml
|
87
|
+
- ".gitignore"
|
88
|
+
- ".travis.yml"
|
94
89
|
- Gemfile
|
95
90
|
- LICENSE
|
96
91
|
- README.md
|
@@ -113,6 +108,7 @@ files:
|
|
113
108
|
- lib/queueing_rabbit/jobs/json_job.rb
|
114
109
|
- lib/queueing_rabbit/logging.rb
|
115
110
|
- lib/queueing_rabbit/misc/inheritable_class_variables.rb
|
111
|
+
- lib/queueing_rabbit/misc/mutex_pool.rb
|
116
112
|
- lib/queueing_rabbit/serializer.rb
|
117
113
|
- lib/queueing_rabbit/tasks.rb
|
118
114
|
- lib/queueing_rabbit/version.rb
|
@@ -153,40 +149,34 @@ files:
|
|
153
149
|
- spec/unit/queueing_rabbit/jobs/abstract_job_spec.rb
|
154
150
|
- spec/unit/queueing_rabbit/jobs/json_job_spec.rb
|
155
151
|
- spec/unit/queueing_rabbit/logging_spec.rb
|
152
|
+
- spec/unit/queueing_rabbit/misc/mutex_pool_spec.rb
|
156
153
|
- spec/unit/queueing_rabbit/serializer_spec.rb
|
157
154
|
- spec/unit/queueing_rabbit/worker_spec.rb
|
158
155
|
- spec/unit/queueing_rabbit_spec.rb
|
159
156
|
homepage: https://github.com/temochka/queueing_rabbit
|
160
157
|
licenses:
|
161
158
|
- MIT
|
159
|
+
metadata: {}
|
162
160
|
post_install_message:
|
163
161
|
rdoc_options:
|
164
|
-
- --charset=UTF-8
|
162
|
+
- "--charset=UTF-8"
|
165
163
|
require_paths:
|
166
164
|
- lib
|
167
165
|
required_ruby_version: !ruby/object:Gem::Requirement
|
168
|
-
none: false
|
169
166
|
requirements:
|
170
|
-
- -
|
167
|
+
- - ">="
|
171
168
|
- !ruby/object:Gem::Version
|
172
169
|
version: '0'
|
173
|
-
segments:
|
174
|
-
- 0
|
175
|
-
hash: 657465743539399174
|
176
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
171
|
requirements:
|
179
|
-
- -
|
172
|
+
- - ">="
|
180
173
|
- !ruby/object:Gem::Version
|
181
174
|
version: '0'
|
182
|
-
segments:
|
183
|
-
- 0
|
184
|
-
hash: 657465743539399174
|
185
175
|
requirements: []
|
186
176
|
rubyforge_project:
|
187
|
-
rubygems_version:
|
177
|
+
rubygems_version: 2.2.1
|
188
178
|
signing_key:
|
189
|
-
specification_version:
|
179
|
+
specification_version: 4
|
190
180
|
summary: QueueingRabbit provides a flexible DSL to interact with RabbitMQ
|
191
181
|
test_files:
|
192
182
|
- spec/integration/asynchronous_batch_publishing_spec.rb
|
@@ -223,6 +213,7 @@ test_files:
|
|
223
213
|
- spec/unit/queueing_rabbit/jobs/abstract_job_spec.rb
|
224
214
|
- spec/unit/queueing_rabbit/jobs/json_job_spec.rb
|
225
215
|
- spec/unit/queueing_rabbit/logging_spec.rb
|
216
|
+
- spec/unit/queueing_rabbit/misc/mutex_pool_spec.rb
|
226
217
|
- spec/unit/queueing_rabbit/serializer_spec.rb
|
227
218
|
- spec/unit/queueing_rabbit/worker_spec.rb
|
228
219
|
- spec/unit/queueing_rabbit_spec.rb
|