Class: Souffle::Application
- Inherits:
-
Object
- Object
- Souffle::Application
- Includes:
- Mixlib::CLI
- Defined in:
- lib/souffle/application.rb
Overview
The souffle application class for both server and worker.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#commands ⇒ Object
The commands that were left unparsed from parse_options.
Class Method Summary collapse
-
.debug_stacktrace(e) ⇒ Object
Present a debug stracktrace upon an error.
-
.exit!(msg, err = -1)) ⇒ Object
Log a fatal error message to both STDERR and the Logger, exit the application with a debug message.
-
.fatal!(msg, err = -1)) ⇒ Object
Log a fatal error message to both STDERR and the Logger, exit the application with a fatal message.
Instance Method Summary collapse
-
#configure_logging ⇒ Object
Configures the logging in a relatively sane fashion.
-
#configure_souffle ⇒ Object
Configure the application throwing a warning when there is no config file.
-
#initialize ⇒ Application
constructor
Initialize the application, setting up default handlers.
-
#reconfigure ⇒ Object
Reconfigure the application and logging.
-
#run ⇒ Object
Run the application itself.
-
#run_application ⇒ Object
Placeholder for run_application, intended to be overridden.
-
#setup_application ⇒ Object
Placeholder for setup_application, intended to be overridden.
Constructor Details
#initialize ⇒ Application
Initialize the application, setting up default handlers.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/souffle/application.rb', line 14 def initialize @commands = [] super trap("TERM") do Souffle::Application.fatal!("SIGTERM received, stopping", 1) end trap("INT") do Souffle::Application.fatal!("SIGINT received, stopping", 2) end trap("QUIT") do Souffle::Log.info("SIGQUIT received, call stack:\n ", caller.join("\n ")) end trap("HUP") do Souffle::Log.info("SIGHUP received, reconfiguring") reconfigure end end |
Instance Attribute Details
#commands ⇒ Object
The commands that were left unparsed from parse_options.
8 9 10 |
# File 'lib/souffle/application.rb', line 8 def commands @commands end |
Class Method Details
.debug_stacktrace(e) ⇒ Object
Present a debug stracktrace upon an error. Gives a readable backtrace with a timestamp.
110 111 112 113 114 115 116 |
# File 'lib/souffle/application.rb', line 110 def debug_stacktrace(e) = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" stacktrace_out = "Generated at #{Time.now.to_s}\n" stacktrace_out += Souffle::Log.debug() end |
Instance Method Details
#configure_logging ⇒ Object
Configures the logging in a relatively sane fashion. Only prints to STDOUT given a valid tty. Does not write to STDOUT when daemonizing.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/souffle/application.rb', line 60 def configure_logging Souffle::Log.init(Souffle::Config[:log_location]) if ( Souffle::Config[:log_location] != STDOUT ) && STDOUT.tty? && ( !Souffle::Config[:daemonize] ) stdout_logger = Logger.new(STDOUT) STDOUT.sync = true stdout_logger.formatter = Souffle::Log.logger.formatter Souffle::Log.loggers << stdout_logger end Souffle::Log.level = Souffle::Config[:log_level] end |
#configure_souffle ⇒ Object
Configure the application throwing a warning when there is no config file.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/souffle/application.rb', line 43 def configure_souffle begin ::File.open(config[:config_file]) { |f| apply_config(f.path) } rescue Errno::ENOENT => error msg = "Did not find the config file: #{config[:config_file]}" msg << ", Using command line options." Souffle::Log.warn "*****************************************" Souffle::Log.warn msg Souffle::Log.warn "*****************************************" end end |
#reconfigure ⇒ Object
Reconfigure the application and logging.
37 38 39 40 |
# File 'lib/souffle/application.rb', line 37 def reconfigure configure_souffle configure_logging end |
#run ⇒ Object
Run the application itself. Configure, setup, and then run.
73 74 75 76 77 |
# File 'lib/souffle/application.rb', line 73 def run reconfigure setup_application run_application end |
#run_application ⇒ Object
Placeholder for run_application, intended to be overridden.
90 91 92 93 |
# File 'lib/souffle/application.rb', line 90 def run_application error_msg = "#{self.to_s}: you must override run_application" raise Souffle::Exceptions::Application, error_msg end |
#setup_application ⇒ Object
Placeholder for setup_application, intended to be overridden.
82 83 84 85 |
# File 'lib/souffle/application.rb', line 82 def setup_application error_msg = "#{self.to_s}: you must override setup_application" raise Souffle::Exceptions::Application, error_msg end |