Class: Toro::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/toro/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = ARGV) ⇒ CLI

Returns a new instance of CLI.



5
6
7
8
# File 'lib/toro/cli.rb', line 5

def initialize(arguments=ARGV)
  @options = arguments_to_options(arguments)
  @manager = Manager.new(@options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/toro/cli.rb', line 3

def options
  @options
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/toro/cli.rb', line 10

def run
  Toro.logger.info 'Starting processing (press Control-C to stop)'

  read_io, write_io = IO.pipe
  
  %w(INT TERM USR1 USR2 TTIN).each do |signal|
    begin
      trap signal do
        write_io.puts(signal)
      end
    rescue ArgumentError
      Toro.logger.debug "Signal #{signal} not supported"
    end
  end

  begin
    @manager.start

    while readable_io = IO.select([read_io])
      signal = readable_io.first[0].gets.strip
      handle_signal(signal)
    end
  rescue Interrupt
    Toro.logger.info 'Shutting down...'
    @manager.stop
  end

  # Explicitly exit so busy Processor threads can't block
  # process shutdown.
  exit 0
end