lib/async_observer/worker.rb in beanstalker-0.1.1 vs lib/async_observer/worker.rb in beanstalker-0.1.2

- old
+ new

@@ -13,15 +13,15 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -require 'async_observer/queue' +require 'beanstalker/queue' -module AsyncObserver; end +module Beanstalker; end -class AsyncObserver::Worker +class Beanstalker::Worker SLEEP_TIME = 60 if !defined?(SLEEP_TIME) # rails loads this file twice class << self attr_accessor :finish @@ -57,11 +57,11 @@ def initialize(top_binding, options = {}) @top_binding = top_binding @stop = false @options = options if @options && @options[:servers] - AsyncObserver::Queue.queue = Beanstalk::Pool.new(@options[:servers]) + Beanstalker::Queue.queue = Beanstalk::Pool.new(@options[:servers]) end end def main_loop trap('TERM') { @stop = true } @@ -72,11 +72,11 @@ end def startup tube = @options[:tube] || "default" logger.info "Using tube #{tube}" - AsyncObserver::Queue.queue.watch(tube) + Beanstalker::Queue.queue.watch(tube) flush_logger end def shutdown do_all_work @@ -88,11 +88,11 @@ rescue Interrupt shutdown end def q_hint - @q_hint || AsyncObserver::Queue.queue + @q_hint || Beanstalker::Queue.queue end # This heuristic is to help prevent one queue from starving. The idea is that # if the connection returns a job right away, it probably has more available. # But if it takes time, then it's probably empty. So reuse the same @@ -110,11 +110,11 @@ end def get_job loop do begin - AsyncObserver::Queue.queue.connect + Beanstalker::Queue.queue.connect self.class.run_before_reserve return reserve_and_set_hint rescue Interrupt => ex raise ex rescue SignalException => ex @@ -134,11 +134,11 @@ end end def dispatch(job) ActiveRecord::Base.verify_active_connections! - return run_ao_job(job) if async_observer_job?(job) + return run_ao_job(job) if beanstalker_job?(job) return run_other(job) end def safe_dispatch(job) logger.info "got #{job.inspect}:\n" + job.body @@ -203,10 +203,10 @@ def run_code(job) eval(job.ybody[:code], @top_binding, "(beanstalk job #{job.id})", 1) end - def async_observer_job?(job) + def beanstalker_job?(job) begin job.ybody[:type] == :rails rescue false end end def run_other(job) logger.info 'trying custom handler'