Sha256: acba80d9e21f7a52783af99a27a4dd748ef0c35410d25ac3b15a7d5849b5e31b
Contents?: true
Size: 1.92 KB
Versions: 4
Compression:
Stored size: 1.92 KB
Contents
module Scout module Realtime class Main INTERVAL=1 LOG_NAME="realtime.log" attr_accessor :running, :runner, :stats_thread # opts: {:port=>xxx} def initialize(opts={}) @port=opts[:port] Scout::Realtime::logger=Logger.new(STDOUT) @stats_thread = Thread.new {} @runner = Scout::Realtime::Runner.new end def start_thread return if @running logger.info("starting stats collector thread") @running = true @stats_thread = Thread.new do while (@running) do @runner.run logger.info("collector thread run ##{@runner.num_runs} ") if @runner.num_runs.to_f % 50.0 == 2 || @runner.num_runs == 1 sleep INTERVAL end end @stats_thread.abort_on_exception = true end def stop_thread! logger.info("stopping collector thread") @running=false end def go_sinatra #@runner.run # sets up the latest_run so we can use it to render the main page #@runner.latest_run=DATA_FOR_TESTING.first logger.info("starting web server ") #['INT', 'TERM'].each do |signal| # trap signal do # puts "got a #{signal} signal -- shutting down :)" # @stats_thread.exit # #Scout::Realtime::WebApp.quit! # # end #end start_thread Scout::Realtime::WebApp.run!(:port=>@port) end def go_webrick logger.info("starting web server ") server = WEBrick::HTTPServer.new(:Port => 5555, :AccessLog => []) server.mount '/', Scout::Realtime::WebServer trap 'INT' do server.shutdown end #start_thread server.start # blocking end # singleton def self.instance(opts={}) @@instance ||= self.new(opts) end def logger Scout::Realtime::logger end end end end
Version data entries
4 entries across 4 versions & 1 rubygems