Class: Droonga::Supervisor
- Inherits:
-
Object
- Object
- Droonga::Supervisor
- Includes:
- Loggable
- Defined in:
- lib/droonga/supervisor.rb
Defined Under Namespace
Classes: WorkerConfiguration, WorkerRunner
Instance Attribute Summary collapse
-
#on_ready ⇒ Object
writeonly
Sets the attribute on_ready.
Instance Method Summary collapse
-
#initialize(loop, n_workers, config) ⇒ Supervisor
constructor
A new instance of Supervisor.
- #start ⇒ Object
- #stop_gracefully ⇒ Object
- #stop_immediately ⇒ Object
Constructor Details
#initialize(loop, n_workers, config) ⇒ Supervisor
Returns a new instance of Supervisor.
24 25 26 27 28 29 |
# File 'lib/droonga/supervisor.rb', line 24 def initialize(loop, n_workers, config) @loop = loop @n_workers = n_workers @config = config @on_ready = nil end |
Instance Attribute Details
#on_ready=(value) ⇒ Object (writeonly)
Sets the attribute on_ready
23 24 25 |
# File 'lib/droonga/supervisor.rb', line 23 def on_ready=(value) @on_ready = value end |
Instance Method Details
#start ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/droonga/supervisor.rb', line 31 def start n_ready_workers = 0 @worker_runners = @n_workers.times.collect do |i| worker_runner = WorkerRunner.new(@loop, i, @config) worker_runner.on_ready = lambda do n_ready_workers += 1 if n_ready_workers == @n_workers @on_ready.call if @on_ready end end worker_runner.start # TODO: support auto re-run worker_runner end end |
#stop_gracefully ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/droonga/supervisor.rb', line 47 def stop_gracefully logger.trace("stop_gracefully: start") n_worker_runners = @worker_runners.size n_done_worker_runners = 0 @worker_runners.each do |worker_runner| worker_runner.stop_gracefully do n_done_worker_runners += 1 if n_done_worker_runners == n_worker_runners yield if block_given? end end end logger.trace("stop_gracefully: done") end |
#stop_immediately ⇒ Object
62 63 64 65 66 |
# File 'lib/droonga/supervisor.rb', line 62 def stop_immediately @worker_runners.each do |worker_runner| worker_runner.stop_immediately end end |