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.
-
#working_processes ⇒ Object
readonly
Returns the value of attribute working_processes.
-
#zombie_processes ⇒ Object
readonly
Returns the value of attribute zombie_processes.
Instance Method Summary collapse
- #all_processes ⇒ Object
-
#initialize(configuration = nil, &block) ⇒ Pool
constructor
A new instance of Pool.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(configuration = nil, &block) ⇒ Pool
Returns a new instance of Pool.
18 19 20 21 22 23 24 |
# File 'lib/spool/pool.rb', line 18 def initialize(configuration=nil, &block) @configuration = configuration || DSL.configure(&block) @working_processes = [] @zombie_processes = Set.new @running = false @actions_queue = [] end |
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 |
#working_processes ⇒ Object
Returns the value of attribute working_processes.
16 17 18 |
# File 'lib/spool/pool.rb', line 16 def working_processes @working_processes end |
#zombie_processes ⇒ Object
Returns the value of attribute zombie_processes.
16 17 18 |
# File 'lib/spool/pool.rb', line 16 def zombie_processes @zombie_processes end |
Instance Method Details
#all_processes ⇒ Object
34 35 36 |
# File 'lib/spool/pool.rb', line 34 def all_processes working_processes + zombie_processes.to_a end |
#running? ⇒ Boolean
26 27 28 |
# File 'lib/spool/pool.rb', line 26 def running? @running end |
#start ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/spool/pool.rb', line 45 def start @running = true handle_signals File.write configuration.pid_file, Process.pid if configuration.pid_file configuration.processes.times.map do working_processes << Spawner.spawn(configuration) end logger.info(self.class) { "SPOOL START => #{format_processes}" } while running? begin 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 rescue Exception => e log_error e end end logger.info(self.class) { "Spool finished successfully!" } end |
#stopped? ⇒ Boolean
30 31 32 |
# File 'lib/spool/pool.rb', line 30 def stopped? !running? end |