Skip to content

Commit 4913f19

Browse files
committed
make new signal handling behavior default in 2.0.0
1 parent 1fadecb commit 4913f19

File tree

3 files changed

+4
-91
lines changed

3 files changed

+4
-91
lines changed

lib/resque/tasks.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
1616
worker.very_verbose = ENV['VVERBOSE']
1717
worker.term_timeout = ENV['RESQUE_TERM_TIMEOUT'] || 4.0
18-
worker.term_child = ENV['TERM_CHILD']
1918
rescue Resque::NoQueueError
2019
abort "set QUEUE env var, e.g. $ QUEUE=critical,high rake resque:work"
2120
end

lib/resque/worker.rb

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class Worker
2222

2323
attr_accessor :term_timeout
2424

25-
# decide whether to use new_kill_child logic
26-
attr_accessor :term_child
27-
2825
attr_writer :to_s
2926

3027
# Returns an array of all worker objects.
@@ -150,7 +147,7 @@ def work(interval = 5.0, &block)
150147
nil
151148
end
152149
else
153-
unregister_signal_handlers if !@cant_fork && term_child
150+
unregister_signal_handlers if !@cant_fork
154151
procline "Processing #{job.queue} since #{Time.now.to_i}"
155152
redis.client.reconnect # Don't share connection with parent
156153
perform(job, &block)
@@ -286,11 +283,7 @@ def register_signal_handlers
286283

287284
begin
288285
trap('QUIT') { shutdown }
289-
if term_child
290-
trap('USR1') { new_kill_child }
291-
else
292-
trap('USR1') { kill_child }
293-
end
286+
trap('USR1') { kill_child }
294287
trap('USR2') { pause_processing }
295288
rescue ArgumentError
296289
warn "Signals QUIT, USR1, USR2, and/or CONT not supported."
@@ -321,36 +314,18 @@ def shutdown
321314
# Kill the child and shutdown immediately.
322315
def shutdown!
323316
shutdown
324-
if term_child
325-
new_kill_child
326-
else
327-
kill_child
328-
end
317+
kill_child
329318
end
330319

331320
# Should this worker shutdown as soon as current job is finished?
332321
def shutdown?
333322
@shutdown
334323
end
335324

336-
# Kills the forked child immediately, without remorse. The job it
337-
# is processing will not be completed.
338-
def kill_child
339-
if @child
340-
log! "Killing child at #{@child}"
341-
if system("ps -o pid,state -p #{@child}")
342-
Process.kill("KILL", @child) rescue nil
343-
else
344-
log! "Child #{@child} not found, restarting."
345-
shutdown
346-
end
347-
end
348-
end
349-
350325
# Kills the forked child immediately with minimal remorse. The job it
351326
# is processing will not be completed. Send the child a TERM signal,
352327
# wait 5 seconds, and then a KILL signal if it has not quit
353-
def new_kill_child
328+
def kill_child
354329
if @child
355330
unless Process.waitpid(@child, Process::WNOHANG)
356331
log! "Sending TERM signal to child #{@child}"

test/worker_test.rb

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -470,66 +470,6 @@ def self.perform
470470
assert_not_equal original_connection, Resque.redis.client.connection.instance_variable_get("@sock")
471471
end
472472

473-
if !defined?(RUBY_ENGINE) || defined?(RUBY_ENGINE) && RUBY_ENGINE != "jruby"
474-
it "old signal handling is the default" do
475-
rescue_time = nil
476-
477-
begin
478-
class LongRunningJob
479-
@queue = :long_running_job
480-
481-
def self.perform( run_time, rescue_time=nil )
482-
Resque.redis.client.reconnect # get its own connection
483-
Resque.redis.rpush( 'sigterm-test:start', Process.pid )
484-
sleep run_time
485-
Resque.redis.rpush( 'sigterm-test:result', 'Finished Normally' )
486-
rescue Resque::TermException => e
487-
Resque.redis.rpush( 'sigterm-test:result', %Q(Caught SignalException: #{e.inspect}))
488-
sleep rescue_time unless rescue_time.nil?
489-
ensure
490-
puts 'fuuuu'
491-
Resque.redis.rpush( 'sigterm-test:final', 'exiting.' )
492-
end
493-
end
494-
495-
Resque.enqueue( LongRunningJob, 5, rescue_time )
496-
497-
worker_pid = Kernel.fork do
498-
# ensure we actually fork
499-
$TESTING = false
500-
# reconnect since we just forked
501-
Resque.redis.client.reconnect
502-
503-
worker = Resque::Worker.new(:long_running_job)
504-
505-
worker.work(0)
506-
exit!
507-
end
508-
509-
# ensure the worker is started
510-
start_status = Resque.redis.blpop( 'sigterm-test:start', 5 )
511-
assert_not_nil start_status
512-
child_pid = start_status[1].to_i
513-
assert_operator child_pid, :>, 0
514-
515-
# send signal to abort the worker
516-
Process.kill('TERM', worker_pid)
517-
Process.waitpid(worker_pid)
518-
519-
# wait to see how it all came down
520-
result = Resque.redis.blpop( 'sigterm-test:result', 5 )
521-
assert_nil result
522-
523-
# ensure that the child pid is no longer running
524-
child_still_running = !(`ps -p #{child_pid.to_s} -o pid=`).empty?
525-
assert !child_still_running
526-
ensure
527-
remaining_keys = Resque.redis.keys('sigterm-test:*') || []
528-
Resque.redis.del(*remaining_keys) unless remaining_keys.empty?
529-
end
530-
end
531-
end
532-
533473
if !defined?(RUBY_ENGINE) || defined?(RUBY_ENGINE) && RUBY_ENGINE != "jruby"
534474
[SignalException, Resque::TermException].each do |exception|
535475
{
@@ -565,7 +505,6 @@ def self.perform( run_time, rescue_time=nil )
565505

566506
worker = Resque::Worker.new(:long_running_job)
567507
worker.term_timeout = 1
568-
worker.term_child = 1
569508

570509
worker.work(0)
571510
exit!

0 commit comments

Comments
 (0)