Class: Backburner::AllqWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/backburner/allq_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tube, allq_wrapper) ⇒ AllqWatcher

Returns a new instance of AllqWatcher.



9
10
11
12
# File 'lib/backburner/allq_wrapper.rb', line 9

def initialize(tube, allq_wrapper)
  @tube = tube
  @allq_wrapper = allq_wrapper
end

Instance Attribute Details

#tubeObject

Returns the value of attribute tube.



7
8
9
# File 'lib/backburner/allq_wrapper.rb', line 7

def tube
  @tube
end

Instance Method Details

#watchObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/backburner/allq_wrapper.rb', line 14

def watch
  Thread.new do
    loop do
      ran = false
      job = @allq_wrapper.get(@tube_name)
      if job.body
        perform(job)
        ran = true
      end
      # Wait if nothing returned
      sleep(rand * 3) unless ran
    end
  end
end