Skip to content

Commit

Permalink
Bugfix: Correct sig handling defined in Rake task
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryandotsmith committed Jan 7, 2014
1 parent f7e2197 commit 28c8fe6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/queue_classic/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 28c8fe6

Please sign in to comment.