Class: DatWorkerPool::WorkerPoolSpy
- Inherits:
-
Object
- Object
- DatWorkerPool::WorkerPoolSpy
- Defined in:
- lib/dat-worker-pool/worker_pool_spy.rb
Instance Attribute Summary collapse
-
#available_worker_count ⇒ Object
Returns the value of attribute available_worker_count.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#num_workers ⇒ Object
readonly
Returns the value of attribute num_workers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#shutdown_called ⇒ Object
readonly
Returns the value of attribute shutdown_called.
-
#shutdown_timeout ⇒ Object
readonly
Returns the value of attribute shutdown_timeout.
-
#start_called ⇒ Object
readonly
Returns the value of attribute start_called.
-
#worker_available ⇒ Object
Returns the value of attribute worker_available.
-
#worker_class ⇒ Object
readonly
Returns the value of attribute worker_class.
-
#worker_params ⇒ Object
readonly
Returns the value of attribute worker_params.
Instance Method Summary collapse
- #add_work(work_item) ⇒ Object (also: #push)
-
#initialize(worker_class, options = nil) ⇒ WorkerPoolSpy
constructor
A new instance of WorkerPoolSpy.
- #shutdown(timeout = nil) ⇒ Object
- #start ⇒ Object
- #work_items ⇒ Object
- #worker_available? ⇒ Boolean
Constructor Details
#initialize(worker_class, options = nil) ⇒ WorkerPoolSpy
Returns a new instance of WorkerPoolSpy.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 12 def initialize(worker_class, = 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 = || {} @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 |
Instance Attribute Details
#available_worker_count ⇒ Object
Returns the value of attribute available_worker_count.
10 11 12 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 10 def available_worker_count @available_worker_count end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 7 def logger @logger end |
#num_workers ⇒ Object (readonly)
Returns the value of attribute num_workers.
8 9 10 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 8 def num_workers @num_workers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 8 def @options end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
7 8 9 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 7 def queue @queue end |
#shutdown_called ⇒ Object (readonly)
Returns the value of attribute shutdown_called.
9 10 11 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 9 def shutdown_called @shutdown_called end |
#shutdown_timeout ⇒ Object (readonly)
Returns the value of attribute shutdown_timeout.
9 10 11 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 9 def shutdown_timeout @shutdown_timeout end |
#start_called ⇒ Object (readonly)
Returns the value of attribute start_called.
9 10 11 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 9 def start_called @start_called end |
#worker_available ⇒ Object
Returns the value of attribute worker_available.
10 11 12 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 10 def worker_available @worker_available end |
#worker_class ⇒ Object (readonly)
Returns the value of attribute worker_class.
8 9 10 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 8 def worker_class @worker_class end |
#worker_params ⇒ Object (readonly)
Returns the value of attribute worker_params.
8 9 10 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 8 def worker_params @worker_params end |
Instance Method Details
#add_work(work_item) ⇒ Object Also known as: push
50 51 52 53 |
# 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 |
#shutdown(timeout = nil) ⇒ Object
44 45 46 47 48 |
# 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 ⇒ Object
39 40 41 42 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 39 def start @start_called = true @queue.dwp_start end |
#work_items ⇒ Object
56 57 58 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 56 def work_items @queue.work_items end |
#worker_available? ⇒ Boolean
60 61 62 |
# File 'lib/dat-worker-pool/worker_pool_spy.rb', line 60 def worker_available? !!@worker_available end |