Class: Chimp::QueueWorker

Inherits:
Object
  • Object
show all
Defined in:
lib/right_chimp/queue/QueueWorker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeQueueWorker

Returns a new instance of QueueWorker.



9
10
11
12
13
# File 'lib/right_chimp/queue/QueueWorker.rb', line 9

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

Instance Attribute Details

#delayObject

Returns the value of attribute delay.



7
8
9
# File 'lib/right_chimp/queue/QueueWorker.rb', line 7

def delay
  @delay
end

#never_exitObject

Returns the value of attribute never_exit.



7
8
9
# File 'lib/right_chimp/queue/QueueWorker.rb', line 7

def never_exit
  @never_exit
end

#retry_countObject

Returns the value of attribute retry_count.



7
8
9
# File 'lib/right_chimp/queue/QueueWorker.rb', line 7

def retry_count
  @retry_count
end

Instance Method Details

#runObject

Grab work items from the ChimpQueue and process them Only stop is @ever_exit is false



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/right_chimp/queue/QueueWorker.rb', line 19

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