Class: Daemonic::Pool
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#desired_workers ⇒ Object
readonly
Returns the value of attribute desired_workers.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
- #count ⇒ Object
- #decrease ⇒ Object
- #decrease! ⇒ Object
- #hup ⇒ Object
- #increase ⇒ Object
- #increase! ⇒ Object
-
#initialize(config) ⇒ Pool
constructor
A new instance of Pool.
- #monitor ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config) ⇒ Pool
Returns a new instance of Pool.
12 13 14 15 16 |
# File 'lib/daemonic/pool.rb', line 12 def initialize(config) @config = config @workers = [] reload_desired_workers end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/daemonic/pool.rb', line 8 def config @config end |
#desired_workers ⇒ Object (readonly)
Returns the value of attribute desired_workers.
10 11 12 |
# File 'lib/daemonic/pool.rb', line 10 def desired_workers @desired_workers end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
10 11 12 |
# File 'lib/daemonic/pool.rb', line 10 def workers @workers end |
Instance Method Details
#count ⇒ Object
46 47 48 |
# File 'lib/daemonic/pool.rb', line 46 def count workers.count { |worker| worker.running? } end |
#decrease ⇒ Object
59 60 61 |
# File 'lib/daemonic/pool.rb', line 59 def decrease workers.pop.stop end |
#decrease! ⇒ Object
63 64 65 66 |
# File 'lib/daemonic/pool.rb', line 63 def decrease! @desired_workers -= 1 decrease end |
#hup ⇒ Object
40 41 42 43 44 |
# File 'lib/daemonic/pool.rb', line 40 def hup reload_desired_workers workers.each(&:hup) start end |
#increase ⇒ Object
50 51 52 |
# File 'lib/daemonic/pool.rb', line 50 def increase workers << start_worker(workers.size) end |
#increase! ⇒ Object
54 55 56 57 |
# File 'lib/daemonic/pool.rb', line 54 def increase! @desired_workers += 1 increase end |
#monitor ⇒ Object
68 69 70 |
# File 'lib/daemonic/pool.rb', line 68 def monitor workers.each(&:monitor) end |
#restart ⇒ Object
26 27 28 29 30 31 |
# File 'lib/daemonic/pool.rb', line 26 def restart workers.each do |worker| worker.restart yield worker if block_given? end end |
#start ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/daemonic/pool.rb', line 18 def start wait_for global_timeout do increase if count < desired_workers count == desired_workers end decrease while count > desired_workers end |
#stop ⇒ Object
33 34 35 36 37 38 |
# File 'lib/daemonic/pool.rb', line 33 def stop workers.each do |worker| worker.stop yield worker if block_given? end end |