class PartTime::Worker

Constants

SHUTDOWN

Attributes

queue[RW]

Public Class Methods

new(queue) click to toggle source
# File lib/part_time/worker.rb, line 7
def initialize(queue)
  @queue = queue
  @on_the_clock = true

  work
end

Public Instance Methods

join() click to toggle source
# File lib/part_time/worker.rb, line 26
def join
  @thread.join
end
on_the_clock?() click to toggle source
# File lib/part_time/worker.rb, line 30
def on_the_clock?
  @on_the_clock
end
work() click to toggle source
# File lib/part_time/worker.rb, line 14
def work
  @thread ||= Thread.new do
    loop do
      job, *args = queue.pop
      break if job == SHUTDOWN
      job.new.perform(*args)
    end

    @on_the_clock = false
  end
end