Class: Akane::Manager
- Inherits:
-
Object
- Object
- Akane::Manager
- Defined in:
- lib/akane/manager.rb
Instance Method Summary collapse
- #handle_signals ⇒ Object
-
#initialize(config) ⇒ Manager
constructor
A new instance of Manager.
- #prepare ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
- #stop_storages ⇒ Object
Constructor Details
#initialize(config) ⇒ Manager
Returns a new instance of Manager.
8 9 10 11 |
# File 'lib/akane/manager.rb', line 8 def initialize(config) @config = config @logger = config.logger end |
Instance Method Details
#handle_signals ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/akane/manager.rb', line 37 def handle_signals @terminating = false begin require 'sigdump/setup' rescue LoadError end on_interrupt = proc do if @terminating @config.log_direct "Terminating forcely..." exit else @terminating = true @config.log_direct "Gracefully stopping..." @recorder.stop! end end trap(:INT, on_interrupt) trap(:TERM, on_interrupt) end |
#prepare ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/akane/manager.rb', line 13 def prepare @logger.info 'Preparing' prepare_receivers prepare_storages prepare_recorder @logger.info "Prepared with #{@storages.size} storage(s) and #{@receivers.size} receiver(s)" end |
#run ⇒ Object
60 61 62 63 64 65 |
# File 'lib/akane/manager.rb', line 60 def run @logger.info "Running..." self.prepare() start() end |
#start ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/akane/manager.rb', line 23 def start @logger.info "Starting receivers..." @receivers.each(&:start) @logger.info "Assigning signal handlers..." handle_signals @logger.info "Starting recorder..." @recorder.run @logger.info "Recorder stopped. Waiting for storages..." stop_storages end |
#stop_storages ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/akane/manager.rb', line 67 def stop_storages @storages.each(&:stop!) loop do not_exitable = @storages.any? do |storage| if storage.exitable? false else @logger.debug "[status] #{storage.name}: #{storage.status || 'not exitable'.freeze}" true end end break unless not_exitable sleep 1 end end |