class DatWorkerPool::WorkerPoolSpy
Attributes
available_worker_count[RW]
logger[R]
num_workers[R]
options[R]
queue[R]
shutdown_called[R]
shutdown_timeout[R]
start_called[R]
worker_available[RW]
worker_class[R]
worker_params[R]
Public Class Methods
new(worker_class, options = nil)
click to toggle source
# File lib/dat-worker-pool/worker_pool_spy.rb, line 12 def initialize(worker_class, options = nil) @worker_class = worker_class if !@worker_class.kind_of?(Class) || !@worker_class.include?(DatWorkerPool::Worker) raise ArgumentError, "worker class must include `#{DatWorkerPool::Worker}`" end @options = options || {} @num_workers = (@options[:num_workers] || DEFAULT_NUM_WORKERS).to_i if @num_workers && @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 @logger = @options[:logger] @worker_params = @options[:worker_params] @available_worker_count = 0 @worker_available = false @start_called = false @shutdown_called = false @shutdown_timeout = nil end
Public Instance Methods
add_work(work_item)
click to toggle source
# File lib/dat-worker-pool/worker_pool_spy.rb, line 50 def add_work(work_item) return if work_item.nil? @queue.dwp_push(work_item) end
Also aliased as: push
shutdown(timeout = nil)
click to toggle source
# File lib/dat-worker-pool/worker_pool_spy.rb, line 44 def shutdown(timeout = nil) @shutdown_called = true @shutdown_timeout = timeout @queue.dwp_shutdown end
start()
click to toggle source
# File lib/dat-worker-pool/worker_pool_spy.rb, line 39 def start @start_called = true @queue.dwp_start end
work_items()
click to toggle source
# File lib/dat-worker-pool/worker_pool_spy.rb, line 56 def work_items @queue.work_items end
worker_available?()
click to toggle source
# File lib/dat-worker-pool/worker_pool_spy.rb, line 60 def worker_available? !!@worker_available end