Class: Readorder::Runner
- Inherits:
-
Object
- Object
- Readorder::Runner
- Defined in:
- lib/readorder/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Runner
constructor
A new instance of Runner.
- #initialize_logging ⇒ Object
- #logger ⇒ Object
- #run(command_name) ⇒ Object
- #setup_signal_handling(cmd) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Runner
Returns a new instance of Runner.
8 9 10 11 |
# File 'lib/readorder/runner.rb', line 8 def initialize( opts = {} ) @options = opts.dup initialize_logging end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/readorder/runner.rb', line 6 def @options end |
Instance Method Details
#initialize_logging ⇒ Object
27 28 29 |
# File 'lib/readorder/runner.rb', line 27 def initialize_logging Readorder::Log.init( ) end |
#logger ⇒ Object
13 14 15 |
# File 'lib/readorder/runner.rb', line 13 def logger @logger ||= ::Logging::Logger[self] end |
#run(command_name) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/readorder/runner.rb', line 31 def run( command_name ) cmd = Command.find( command_name ).new( @options ) begin setup_signal_handling( cmd ) cmd.before cmd.run rescue => e logger.error "while running #{command_name} : #{e.}" e.backtrace.each do |l| logger.debug l end cmd.error ensure cmd.after end end |
#setup_signal_handling(cmd) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/readorder/runner.rb', line 17 def setup_signal_handling( cmd ) %w[ INT QUIT TERM ].each do |s| Signal.trap( s ) do logger.info "received signal #{s} -- shutting down" cmd.shutdown exit 1 end end end |