Class: Messaging::CLI
- Inherits:
-
Object
- Object
- Messaging::CLI
- Defined in:
- lib/messaging/cli.rb
Overview
Starts up the consumer supervisor and handles signals
Constant Summary collapse
- SIGNALS =
%i[INT TERM QUIT].freeze
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
-
#wait_for_signal ⇒ Object
See www.sitepoint.com/the-self-pipe-trick-explained/ for background on this.
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
11 12 13 14 15 |
# File 'lib/messaging/cli.rb', line 11 def initialize @signal_queue = [] @reader, @writer = IO.pipe @consumer_supervisor = Messaging::ConsumerSupervisor.new end |
Instance Method Details
#run ⇒ Object
17 18 19 20 21 |
# File 'lib/messaging/cli.rb', line 17 def run setup_signals consumer_supervisor.start wait_for_signal end |
#wait_for_signal ⇒ Object
See www.sitepoint.com/the-self-pipe-trick-explained/ for background on this
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/messaging/cli.rb', line 24 def wait_for_signal loop do case signal_queue.pop when *SIGNALS consumer_supervisor.stop break when "USR1" consumer_supervisor.status else ready = IO.select([reader, writer]) # drain the self-pipe so it won't be returned again next time reader.read_nonblock(1) if ready[0].include?(reader) end end end |