Class: Perus::Server::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/perus/server/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options_path = DEFAULT_SERVER_OPTIONS_PATH, environment = 'development') ⇒ Server

Returns a new instance of Server.



21
22
23
24
25
26
27
28
# File 'lib/perus/server/server.rb', line 21

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
end

Class Method Details

.load_options(path = DEFAULT_SERVER_OPTIONS_PATH) ⇒ Object



55
56
57
# File 'lib/perus/server/server.rb', line 55

def self.load_options(path = DEFAULT_SERVER_OPTIONS_PATH)
    options.load(path, DEFAULT_SERVER_OPTIONS)
end

.optionsObject



51
52
53
# File 'lib/perus/server/server.rb', line 51

def self.options
    @options ||= Perus::Options.new
end

.ping_queueObject



38
39
40
41
42
43
44
45
# File 'lib/perus/server/server.rb', line 38

def self.ping_queue
    # ping data is processed in a thread pool
    @ping_queue ||= Concurrent::ThreadPoolExecutor.new(
        min_threads: 2,
        max_threads: 2,
        max_queue: 0
    )
end

.shutdownObject



47
48
49
# File 'lib/perus/server/server.rb', line 47

def self.shutdown
    @ping_queue.shutdown
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
# File 'lib/perus/server/server.rb', line 30

def run
    Thin::Server.start(
        self.class.options.listen,
        self.class.options.port.to_i,
        App
    )
end