lib/logstash/inputs/mongoprofile.rb in logstash-input-mongoprofile-0.1.3 vs lib/logstash/inputs/mongoprofile.rb in logstash-input-mongoprofile-0.1.4

- old
+ new

@@ -22,29 +22,38 @@ public def register @host = Socket.gethostname @controller = Controller.new(@host, @url, 'system.profile', 1000, @path, @client_host) - end # def register + end + # def register + def run(queue) # we can abort the loop if stop? becomes true while !stop? + begin - @controller.get_next_events.each do |event| - @logger.info("Send event #{event}") + @controller.get_next_events.each do |event| + @logger.info("Send event #{event}") - decorate(event) - queue << event - end + decorate(event) + queue << event + end - # because the sleep interval can be big, when shutdown happens - # we want to be able to abort the sleep - # Stud.stoppable_sleep will frequently evaluate the given block - # and abort the sleep(@interval) if the return value is true - Stud.stoppable_sleep(@interval) { stop? } + # because the sleep interval can be big, when shutdown happens + # we want to be able to abort the sleep + # Stud.stoppable_sleep will frequently evaluate the given block + # and abort the sleep(@interval) if the return value is true + Stud.stoppable_sleep(@interval) {stop?} + rescue => e + @logger.warn('MongoProfile input threw an exception, restarting', :exception => e) + @logger.warn(e.backtrace.inspect) + end end # loop - end # def run + end + + # def run def stop # nothing to do in this case so it is not necessary to define stop # examples of common "stop" tasks: # * close sockets (unblocking blocking reads/accepts) \ No newline at end of file