Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit 6272a99

Browse files
committed
Make the queue manager more robust at handling deceased queues.
1 parent e5828af commit 6272a99

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

code/queue.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def self.log(path, mesg)
125125
File.open(path + '/queue.log', "a") do |f|
126126
f.write("#{Process.pid} - #{Time.now} - #{mesg}\n")
127127
end
128+
rescue Exception
129+
$stderr.write("Cannot log to #{path}: #{Process.pid} - #{Time.now} - #{mesg}\n")
128130
end
129131

130132
def self.start_process(options)
@@ -180,6 +182,11 @@ def self.start_process(options)
180182
worker.num_restarts = 0
181183
worker.options = options
182184
worker
185+
186+
# If anything went wrong at all log it and return nil.
187+
rescue Exception
188+
self.log("Failed to start worker #{options.inspect}: #{$!}")
189+
nil
183190
end
184191

185192
def self.close_all_fds(exclude_fds)

code/queuemgr.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,11 @@ def run_loop
341341
#log(io_list.inspect)
342342
log('sleeping')
343343
begin
344-
ready, _, _ = IO.select(io_list, nil, nil, 60)
345-
rescue Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
344+
ready, _, _ = IO.select(io_list, nil, io_list, 60)
345+
rescue SystemCallError # This is the parent for all Errno::EFOO exceptions
346346
log("error on SELECT #{$!}")
347+
closed_sockets = io_list.delete_if { |i| i.closed? }
348+
log("removing closed sockets #{closed_sockets.inspect} from io_list")
347349
retry
348350
end
349351

@@ -392,8 +394,10 @@ def run_loop
392394
log("FAILED [ #{worker.name} - too many restarts. Not restarting ]")
393395
else
394396
new_worker = RQ::Queue.start_process(worker.options)
395-
log("STARTED [ #{new_worker.name} - #{new_worker.pid} ]")
396-
worker = new_worker
397+
if new_worker
398+
log("STARTED [ #{new_worker.name} - #{new_worker.pid} ]")
399+
worker = new_worker
400+
end
397401
end
398402
elsif worker.status == "DELETE"
399403
RQ::Queue.delete(worker.name)

0 commit comments

Comments
 (0)