Module: RoMQ::Helpers
- Included in:
- Connection
- Defined in:
- lib/romq/helpers.rb
Constant Summary collapse
- DEBUG =
ENV.fetch('DEBUG') { false }
Instance Method Summary collapse
- #flush_logs_periodically ⇒ Object
- #logger ⇒ Object
- #stop ⇒ Object
-
#stop_gracefully ⇒ Object
If you need to tear down any other connections, keep track of their status via @connections_to_stop.
Instance Method Details
#flush_logs_periodically ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/romq/helpers.rb', line 8 def flush_logs_periodically Proc.new do |seconds = Config::LOG_EVERY| EM.add_periodic_timer(seconds) do EM.defer { $stdout.flush } end end end |
#logger ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/romq/helpers.rb', line 36 def logger return @logger if @logger @logger = Logger.new(STDOUT) @logger.level = DEBUG ? Logger::DEBUG : Logger::INFO @logger end |
#stop ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/romq/helpers.rb', line 16 def stop if @connections_to_stop <= 0 EM.stop if EM.reactor_running? logger.info("Stopping #{self.class} service... done!") exit 0 else logger.info("Waiting on #{@connections_to_stop} connection(s) to close...") end end |
#stop_gracefully ⇒ Object
If you need to tear down any other connections, keep track of their status via @connections_to_stop
28 29 30 31 32 33 34 |
# File 'lib/romq/helpers.rb', line 28 def stop_gracefully @connections_to_stop = 0 Signal.trap "SIGTERM", stop Signal.trap "SIGINT", stop Signal.trap "SIGQUIT", stop end |