Sha256: b098fa4c595e13fbfa8f2c524d5561ea8441b2c43322ac4470a8fe9fcc1993e7

Contents?: true

Size: 1.22 KB

Versions: 67

Compression:

Stored size: 1.22 KB

Contents

module Delayed
  class Worker
    SLEEP = 5

    cattr_accessor :logger
    self.logger = if defined?(Merb::Logger)
                    Merb.logger
                  elsif defined?(RAILS_DEFAULT_LOGGER)
                    RAILS_DEFAULT_LOGGER
                  end

    def initialize(options={})
      @quiet = options[:quiet]
      Delayed::Job.min_priority = options[:min_priority] if options.has_key?(:min_priority)
      Delayed::Job.max_priority = options[:max_priority] if options.has_key?(:max_priority)
    end

    def start
      say "*** Starting job worker #{Delayed::Job.worker_name}"

      trap('TERM') { say 'Exiting...'; $exit = true }
      trap('INT')  { say 'Exiting...'; $exit = true }

      loop do
        result = nil

        realtime = Benchmark.realtime do
          result = Delayed::Job.work_off
        end

        count = result.sum

        break if $exit

        if count.zero?
          sleep(SLEEP)
        else
          say "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
        end

        break if $exit
      end

    ensure
      Delayed::Job.clear_locks!
    end

    def say(text)
      puts text unless @quiet
      logger.info text if logger
    end

  end
end

Version data entries

67 entries across 67 versions & 14 rubygems

Version Path
DrMark-thinking-sphinx-1.1.14 vendor/delayed_job/lib/delayed/worker.rb
DrMark-thinking-sphinx-1.1.15 vendor/delayed_job/lib/delayed/worker.rb
DrMark-thinking-sphinx-1.1.6 vendor/delayed_job/lib/delayed/worker.rb
DrMark-thinking-sphinx-1.2.5 vendor/delayed_job/lib/delayed/worker.rb
DrMark-thinking-sphinx-1.2.6 vendor/delayed_job/lib/delayed/worker.rb
bterlson-thinking-sphinx-1.2.8 vendor/delayed_job/lib/delayed/worker.rb
dpickett-thinking-sphinx-1.1.12 vendor/delayed_job/lib/delayed/worker.rb
dpickett-thinking-sphinx-1.1.23 vendor/delayed_job/lib/delayed/worker.rb
dpickett-thinking-sphinx-1.1.4 vendor/delayed_job/lib/delayed/worker.rb
ebeigarts-thinking-sphinx-1.1.21 vendor/delayed_job/lib/delayed/worker.rb
ebeigarts-thinking-sphinx-1.1.22 vendor/delayed_job/lib/delayed/worker.rb
ebeigarts-thinking-sphinx-1.2.10 vendor/delayed_job/lib/delayed/worker.rb
factorylabs-thinking-sphinx-1.2.7 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.0 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.1 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.10 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.11 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.12 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.14 vendor/delayed_job/lib/delayed/worker.rb
freelancing-god-thinking-sphinx-1.1.15 vendor/delayed_job/lib/delayed/worker.rb