Created
February 16, 2010 12:59
Revisions
-
simon-engledew revised this gist
Mar 10, 2010 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ #!/usr/bin/env ruby if GC.respond_to?(:copy_on_write_friendly=); GC.copy_on_write_friendly = true; end def pidfile @pidfile ||= File.expand_path(File.join('..', '..', 'tmp', 'pids', 'consumer.pid'), __FILE__) end -
simon-engledew created this gist
Feb 16, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ #!/usr/bin/env ruby def pidfile @pidfile ||= File.expand_path(File.join('..', '..', 'tmp', 'pids', 'consumer.pid'), __FILE__) end case ARGV.first when 'start' then $stdout.puts('starting consumer') require 'rubygems' require 'rake' ENV['QUEUES'] ||= 'critical,source' ENV['COUNT'] ||= '4' ENV['RAILS_ENV'] ||= 'production' load(File.expand_path(File.join('..', '..', 'Rakefile'), __FILE__)) Process.detach(consumer = Process.fork do begin r, w = IO.pipe ENV['COUNT'].to_i.times do Process.fork do begin w.close Thread.new { r.read; exit } Rake::Task['resque:work'].invoke rescue Exception => e $stdout.puts([e, *e.backtrace].join($/)) end end end Process.waitall rescue Exception => e $stdout.puts([e, *e.backtrace].join($/)) end end) %x(echo "#{consumer}" > #{pidfile}) when 'stop' then %x(kill `cat #{pidfile}`) %x(rm #{pidfile}) else puts 'usage: script/consumer start|stop' end