class DatWorkerPool
Constants
- DEFAULT_NUM_WORKERS
- MIN_WORKERS
- ShutdownError
this error should never be “swallowed”, if it is caught be sure to re-raise it so the workers shutdown; otherwise workers will get killed (`Thread#kill`) by ruby which can cause a problems
- VERSION
Attributes
queue[R]
Public Class Methods
new(worker_class, options = nil)
click to toggle source
# File lib/dat-worker-pool.rb, line 15 def initialize(worker_class, options = nil) if !worker_class.kind_of?(Class) || !worker_class.include?(DatWorkerPool::Worker) raise ArgumentError, "worker class must include `#{DatWorkerPool::Worker}`" end options ||= {} num_workers = (options[:num_workers] || DEFAULT_NUM_WORKERS).to_i if num_workers < MIN_WORKERS raise ArgumentError, "number of workers must be at least #{MIN_WORKERS}" end @queue = options[:queue] || begin require 'dat-worker-pool/default_queue' DatWorkerPool::DefaultQueue.new end @runner = DatWorkerPool::Runner.new({ :num_workers => num_workers, :logger => options[:logger], :queue => @queue, :worker_class => worker_class, :worker_params => options[:worker_params] }) end
Public Instance Methods
add_work(work_item)
click to toggle source
# File lib/dat-worker-pool.rb, line 48 def add_work(work_item) return if work_item.nil? @queue.dwp_push work_item end
Also aliased as: push
available_worker_count()
click to toggle source
# File lib/dat-worker-pool.rb, line 58 def available_worker_count @runner.available_worker_count end
shutdown(timeout = nil)
click to toggle source
# File lib/dat-worker-pool.rb, line 44 def shutdown(timeout = nil) @runner.shutdown(timeout) end
start()
click to toggle source
# File lib/dat-worker-pool.rb, line 40 def start @runner.start end
work_items()
click to toggle source
# File lib/dat-worker-pool.rb, line 54 def work_items @queue.work_items end
worker_available?()
click to toggle source
# File lib/dat-worker-pool.rb, line 62 def worker_available? @runner.worker_available? end