module DatWorkerPool::Queue::InstanceMethods

Public Instance Methods

dwp_pop() click to toggle source
# File lib/dat-worker-pool/queue.rb, line 46
def dwp_pop
  return if self.shutdown?
  pop!
end
dwp_push(*args) click to toggle source
# File lib/dat-worker-pool/queue.rb, line 41
def dwp_push(*args)
  raise "Unable to add work when shut down" if self.shutdown?
  push!(*args)
end
dwp_shutdown() click to toggle source
# File lib/dat-worker-pool/queue.rb, line 28
def dwp_shutdown
  self.dwp_signal_shutdown
  shutdown!
end
dwp_signal_shutdown() click to toggle source
# File lib/dat-worker-pool/queue.rb, line 24
def dwp_signal_shutdown
  @dwp_running = false
end
dwp_start() click to toggle source
# File lib/dat-worker-pool/queue.rb, line 19
def dwp_start
  @dwp_running = true
  start!
end
running?() click to toggle source
# File lib/dat-worker-pool/queue.rb, line 33
def running?
  !!@dwp_running
end
shutdown?() click to toggle source
# File lib/dat-worker-pool/queue.rb, line 37
def shutdown?
  !self.running?
end
work_items() click to toggle source

overwrite this method to add custom logic for reading the current work items on the queue

# File lib/dat-worker-pool/queue.rb, line 15
def work_items
  raise NotImplementedError
end

Private Instance Methods

pop!() click to toggle source

overwrite this method to add custom pop logic; this has to be overwritten or the workers will not be able to get work that needs to be processed; this is intended to sleep the worker threads (see the default queue for an example using mutexes and condition variables); if this returns `nil` the workers will ignore it and go back to sleep, `nil` is not a valid work item to process; also check if the queue is shutdown when waking up workers, you probably don't want to hand-off work while everything is shutting down

# File lib/dat-worker-pool/queue.rb, line 82
def pop!
  raise NotImplementedError
end
push!(*args) click to toggle source

overwrite this method to add custom push logic; this doesn't have to be overwritten but if it isn't, you will not be able to add work items using the queue (and the `add_work` method on `DatWorkerPool` will not work); more than likely this should add work to the queue and “signal” the workers so they know to process it (see the default queue for an example using mutexes and condition variables)

# File lib/dat-worker-pool/queue.rb, line 70
def push!(*args)
  raise NotImplementedError
end
shutdown!() click to toggle source

overwrite this method to add custom shutdown logic; this is a no-op by default because we don't require a queue to have custom shutdown logic; more than likely you will want to use this to “wakeup” worker threads that are sleeping waiting to pop work from the queue (see the default queue for an example using mutexes and condition variables)

# File lib/dat-worker-pool/queue.rb, line 62
def shutdown!; end
start!() click to toggle source

overwrite this method to add custom start logic; this is a no-op by default because we don't require a queue to have custom start logic

# File lib/dat-worker-pool/queue.rb, line 55
def start!; end