Class: GlassOctopus::Runner
- Inherits:
-
Object
- Object
- GlassOctopus::Runner
- Includes:
- Singleton
- Defined in:
- lib/glass_octopus/runner.rb
Overview
A very simple runner that takes an app and handles graceful shutdown for SIGINT and SIGTERM.
The #run method alters the state of the process globally and irreversibly by registering signal handlers. The Runner class is a singleton and can only be started once.
Runner runs the application in the main thread. When a signal hits the process the control is transferred to the signal handler which will raise an Interrupt exception which kicks off the graceful shutdown. During shutdown no more messages are read because everything happens in the main thread.
Runner does not provide any meaningful error handling. Errors are logged and then the process exits with status code 1.
Class Method Summary collapse
-
.run(app) ⇒ void
Shortcut to #run.
Instance Method Summary collapse
-
#run(app) ⇒ void
Starts the application and blocks until the process gets a SIGTERM or SIGINT signal.
-
#running? ⇒ Boolean
Determines whether the application is running or not.
Class Method Details
.run(app) ⇒ void
This method returns an undefined value.
Shortcut to #run.
23 24 25 |
# File 'lib/glass_octopus/runner.rb', line 23 def self.run(app) instance.run(app) end |
Instance Method Details
#run(app) ⇒ void
This method returns an undefined value.
Starts the application and blocks until the process gets a SIGTERM or SIGINT signal.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/glass_octopus/runner.rb', line 32 def run(app) return if running? running! # To support JRuby Ctrl+C as MRI does. # See: https://github.com/jruby/jruby/issues/1639 trap(:INT) { Thread.main.raise Interrupt } trap(:TERM) { Thread.main.raise Interrupt } app.run rescue Interrupt app.logger.info("Shutting down...") app.shutdown app.logger.info("Bye.") rescue => ex app.logger.fatal("#{ex.class} - #{ex.}:") app.logger.fatal(ex.backtrace.join("\n")) if ex.backtrace exit(1) end |
#running? ⇒ Boolean
Determines whether the application is running or not.
54 55 56 |
# File 'lib/glass_octopus/runner.rb', line 54 def running? @running end |