From 28c8fe6b75176e8a53e115f7ff63cb6de30681eb Mon Sep 17 00:00:00 2001 From: Ryan Smith Date: Mon, 6 Jan 2014 23:34:26 -0800 Subject: [PATCH] Bugfix: Correct sig handling defined in Rake task The queue_classic rake task will now respond to the following signals: * INT - Instructs the worker to stop accepting new jobs. * INT - If INT is sent twice (or the worker's @running ivar is false) exit(1). * TERM - Set the worker's @running ivar to false. --- lib/queue_classic/tasks.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/queue_classic/tasks.rb b/lib/queue_classic/tasks.rb index adcc14da..825f771f 100644 --- a/lib/queue_classic/tasks.rb +++ b/lib/queue_classic/tasks.rb @@ -8,9 +8,22 @@ namespace :qc do desc "Start a new worker for the (default or $QUEUE) queue" task :work => :environment do - trap('INT') {exit} - trap('TERM') {@worker.stop} @worker = QC::Worker.new + + trap('INT') do + $stderr.puts("Received INT. Shutting down.") + if !@worker.running + $stderr.puts("Worker has stopped running. Exit.") + exit(1) + end + @worker.stop + end + + trap('TERM') do + $stderr.puts("Received Term. Shutting down.") + @worker.stop + end + @worker.start end