lib/daemonic/producer.rb in daemonic-0.1.2 vs lib/daemonic/producer.rb in daemonic-0.1.3

- old
+ new

@@ -11,12 +11,25 @@ @logger = options[:logger] @running = true end def run + logger.info "Starting producer with #{concurrency} consumer threads." + at_exit { + last_error = $! + if last_error + msg = "Shutting down: #{last_error.inspect}\n#{last_error.backtrace.join("\n")}" + logger.fatal msg + $stdout.puts msg + else + logger.fatal "Shutting down" + $stdout.puts "Shutting down" + end + } + Signal.trap("INT") { stop } Signal.trap("TERM") { stop } pool = Pool.new(self) @@ -29,20 +42,20 @@ pool.stop end producer.join - logger.info { "Shutting down" } - end def stop @running = false end def logger - @logger ||= Logger.new(@options[:log] || STDOUT).tap { |logger| - logger.level = @options[:log_level] || Logger::INFO + @logger ||= @options.fetch(:logger) { + Logger.new(@options[:log] || STDOUT).tap { |logger| + logger.level = @options[:log_level] || Logger::INFO + } } end end end