Class: QC::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/queue_classic/worker.rb

Instance Method Summary collapse

Constructor Details

#initializeWorker

Returns a new instance of Worker.



4
5
6
# File 'lib/queue_classic/worker.rb', line 4

def initialize
  @worker_id = rand(1000)
end

Instance Method Details

#startObject



8
9
10
11
# File 'lib/queue_classic/worker.rb', line 8

def start
  puts "#{@worker_id} ready for work"
  loop { work }
end

#workObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/queue_classic/worker.rb', line 13

def work
  job = QC.dequeue
  # if we are here, dequeue has unblocked
  # and we may have a job.
  if job
    puts "#{@worker_id} working job"
    QC.work(job)
  end

end