Class: Daneel::Server
- Inherits:
-
Object
- Object
- Daneel::Server
- Defined in:
- lib/daneel/server.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #run_self_ping ⇒ Object
- #run_server ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 13 14 15 16 |
# File 'lib/daneel/server.rb', line 8 def initialize( = {}) require 'daneel/web' @logger = [:logger] || Daneel::Logger.new @options = {:app => Daneel::Web, :server => "puma"}.merge() @options[:port] = ENV["PORT"] if ENV["PORT"] # Rack expects the port key to be capitalized. Sad day. @options[:Port] = @options.delete(:port) if @options[:port] logger.debug "Server with options: #{@options}" end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/daneel/server.rb', line 6 def logger @logger end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 |
# File 'lib/daneel/server.rb', line 18 def run Thread.new { run_server } sleep 0.1 # boot server before allowing possible interaction Thread.new { run_self_ping } end |
#run_self_ping ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/daneel/server.rb', line 28 def run_self_ping return unless ENV['HEROKU_URL'] uri = URI(ENV['HEROKU_URL']) http = Net::HTTP::Persistent.new 'daneel' loop do http.request uri sleep (60 * 20) # 20m end end |
#run_server ⇒ Object
24 25 26 |
# File 'lib/daneel/server.rb', line 24 def run_server Rack::Server.start(@options) end |