Class: Spool::Pool
- Inherits:
-
Object
- Object
- Spool::Pool
- Defined in:
- lib/spool/pool.rb
Constant Summary collapse
- CHECK_TIMEOUT =
0.01- 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.
Instance Method Summary collapse
-
#initialize(configuration = nil, &block) ⇒ Pool
constructor
A new instance of Pool.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/spool/pool.rb', line 16 def configuration @configuration end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
16 17 18 |
# File 'lib/spool/pool.rb', line 16 def processes @processes end |
Instance Method Details
#running? ⇒ Boolean
25 26 27 |
# File 'lib/spool/pool.rb', line 25 def running? @running end |
#start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/spool/pool.rb', line 40 def start @running = true handle_signals File.write configuration.pid_file, Process.pid if configuration.pid_file configuration.processes.times.map do processes << Spawner.spawn(configuration) end logger.info(self.class) { "SPOOL START childrens: #{processes.map(&:pid)}" } while running? action = actions_queue.pop if action logger.info(self.class) { "Starting action #{action[:name]} with params: [#{action[:args].join(', ')}]" } send action[:name], *action[:args] end if running? check_status sleep CHECK_TIMEOUT end end logger.info(self.class) { "Spool finished successfully!" } end |
#stopped? ⇒ Boolean
29 30 31 |
# File 'lib/spool/pool.rb', line 29 def stopped? !running? end |