Sha256: ea2adc540cea3f80ce21234e057d7227c9967b8672c91b32ee8c9d7c55619614

Contents?: true

Size: 1.13 KB

Versions: 6

Compression:

Stored size: 1.13 KB

Contents

#
# QueueWorker objects take work from the Queue and process it
# Each QueueWorker runs in its own thread... nothing fancy going on here
#
module Chimp
  class QueueWorker
    attr_accessor :delay, :retry_count, :never_exit

    def initialize
      @delay = 0
      @retry_count = 0
      @never_exit = true
    end

    #
    # Grab work items from the ChimpQueue and process them
    # Only stop is @ever_exit is false
    #
    def run
      while @never_exit
        work_item = ChimpQueue.instance.shift()

        begin
          if work_item != nil
            work_item.retry_count = @retry_count
            work_item.owner = Thread.current.object_id
            work_item.run
            sleep @delay
          else
            sleep 1
          end

        #
        # the rest_connection gem raises RuntimeErrors so we need to
        # rescue Exception here
        #
        rescue Exception => ex
          Log.error "Exception in QueueWorker.run: #{ex}"
          Log.debug ex.inspect
          Log.debug ex.backtrace

          work_item.status = Executor::STATUS_ERROR
          work_item.error = ex
        end
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
right_chimp-1.1.3 lib/right_chimp/queue/QueueWorker.rb
right_chimp-1.1.2 lib/right_chimp/queue/QueueWorker.rb
right_chimp-1.1.1 lib/right_chimp/queue/QueueWorker.rb
right_chimp-1.1.0 lib/right_chimp/queue/QueueWorker.rb
right_chimp-1.0.9 lib/right_chimp/queue/QueueWorker.rb
right_chimp-1.0.8 lib/right_chimp/queue/QueueWorker.rb