class Perus::Server::Server

Public Class Methods

load_options(path = DEFAULT_SERVER_OPTIONS_PATH) click to toggle source
# File lib/perus/server/server.rb, line 69
def self.load_options(path = DEFAULT_SERVER_OPTIONS_PATH)
    options.load(path, DEFAULT_SERVER_OPTIONS)
end
new(options_path = DEFAULT_SERVER_OPTIONS_PATH, environment = 'development') click to toggle source
# File lib/perus/server/server.rb, line 29
def initialize(options_path = DEFAULT_SERVER_OPTIONS_PATH, environment = 'development')
    self.class.load_options(options_path)
    ENV['RACK_ENV'] = environment

    # initialise/migrate the db and start cleanup/caching timers
    DB.start
    DB.start_timers

    # ping data is processed in a thread pool
    Thread.new do
        while true
            ping = Server.ping_queue.pop
            begin
                ping.call
            rescue => e
                puts e.inspect
                if e.backtrace.is_a?(Array)
                    puts e.backtrace.join("\n") + "\n"
                end
            end
        end
    end
end
options() click to toggle source
# File lib/perus/server/server.rb, line 65
def self.options
    @options ||= Perus::Options.new
end
ping_queue() click to toggle source
# File lib/perus/server/server.rb, line 61
def self.ping_queue
    @ping_queue ||= Queue.new
end

Public Instance Methods

run() click to toggle source
# File lib/perus/server/server.rb, line 53
def run
    Thin::Server.start(
        self.class.options.listen,
        self.class.options.port.to_i,
        App
    )
end