Class: Spool::Pool
- Inherits:
-
Object
- Object
- Spool::Pool
- Defined in:
- lib/spool/pool.rb
Constant Summary collapse
- SIGNALS =
{ INT: :stop!, TERM: :stop!, QUIT: :stop, HUP: :reload, USR2: :restart, TTIN: :incr, TTOU: :decr }
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
Instance Method Summary collapse
- #decr(count = 1) ⇒ Object
- #incr(count = 1) ⇒ Object
-
#initialize(configuration = nil, &block) ⇒ Pool
constructor
A new instance of Pool.
- #reload ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop(timeout = 0) ⇒ Object
- #stop! ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
14 15 16 |
# File 'lib/spool/pool.rb', line 14 def configuration @configuration end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
14 15 16 |
# File 'lib/spool/pool.rb', line 14 def processes @processes end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
14 15 16 |
# File 'lib/spool/pool.rb', line 14 def runner @runner end |
Instance Method Details
#decr(count = 1) ⇒ Object
66 67 68 |
# File 'lib/spool/pool.rb', line 66 def decr(count=1) configuration.processes -= count end |
#incr(count = 1) ⇒ Object
62 63 64 |
# File 'lib/spool/pool.rb', line 62 def incr(count=1) configuration.processes += count end |
#reload ⇒ Object
70 71 72 |
# File 'lib/spool/pool.rb', line 70 def reload @configuration = DSL.configure configuration.source_file if configuration.source_file end |
#restart ⇒ Object
74 75 76 |
# File 'lib/spool/pool.rb', line 74 def restart processes.each(&:stop) end |
#start ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/spool/pool.rb', line 30 def start @started = true handle_signals File.write configuration.pidfile, Process.pid if configuration.pidfile configuration.processes.times.map do processes << Spawner.spawn(configuration) end while @started check_status sleep 0.05 end end |
#started? ⇒ Boolean
22 23 24 |
# File 'lib/spool/pool.rb', line 22 def started? @started end |
#stop(timeout = 0) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/spool/pool.rb', line 47 def stop(timeout=0) processes.each(&:stop) Timeout.timeout(timeout) { wait_for_stopped processes } rescue Timeout::Error ensure stop! end |
#stop! ⇒ Object
55 56 57 58 59 60 |
# File 'lib/spool/pool.rb', line 55 def stop! processes.each(&:kill) processes.clear File.delete configuration.pidfile if File.exists? configuration.pidfile @started = false end |
#stopped? ⇒ Boolean
26 27 28 |
# File 'lib/spool/pool.rb', line 26 def stopped? !started? end |