Sha256: 7562cf80a5702f9693f29c5411f52412091480875cb8a97355d29e5064e7728f

Contents?: true

Size: 1.02 KB

Versions: 25

Compression:

Stored size: 1.02 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

        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

25 entries across 25 versions & 1 rubygems

Version Path
right_chimp-2.1.24 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.22.2 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.22.1 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.22 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.21 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.19.1 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.19 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.18 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.17 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.15 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.14 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.13 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.12 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.10 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.8 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.7 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.6 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.5 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.4 lib/right_chimp/queue/QueueWorker.rb
right_chimp-2.1.3 lib/right_chimp/queue/QueueWorker.rb