Class: Thrifty::HTTP::Server::PumaServer
- Inherits:
-
Object
- Object
- Thrifty::HTTP::Server::PumaServer
- Defined in:
- lib/thrifty/http_server/puma_server.rb
Constant Summary collapse
- DEFAULT_PORT =
ENV['PORT'].to_i > 0 ? ENV['PORT'] : 8080
- DEFAULT_IP =
'0.0.0.0'- DEFAULT_MIN_TH =
20- DEFAULT_MAX_TH =
20
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ PumaServer
constructor
A new instance of PumaServer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ PumaServer
Returns a new instance of PumaServer.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/thrifty/http_server/puma_server.rb', line 13 def initialize(={}) port = [:port] || DEFAULT_PORT ip = [:ip] || DEFAULT_IP min = [:min] || DEFAULT_MIN_TH max = [:max] || DEFAULT_MAX_TH name = [:name] || 'Puma' @log = Thrifty.get_logger(name) @bind = "#{ip}:#{port}" @lock = Mutex.new app = ::Rack::Builder.new do if [:err] != false use ErrMiddleware, name end if [:log] != false use LogMiddleware, name end use Rack::Lint yield self end @server = Puma::Server.new(app) @server.add_tcp_listener ip, port @server.min_threads = min @server.max_threads = max Thrifty::Signals.register(method(:stop)) end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
6 7 8 |
# File 'lib/thrifty/http_server/puma_server.rb', line 6 def log @log end |
Instance Method Details
#start ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/thrifty/http_server/puma_server.rb', line 45 def start @lock.synchronize do unless @thread log.info "starting", version: Puma::Server::VERSION, bind: @bind, threads: "#{@server.min_threads}:#{@server.max_threads}" @thread = @server.run end end end |
#stop ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/thrifty/http_server/puma_server.rb', line 54 def stop @lock.synchronize do if @thread log.info "stopping" @server.stop(true) @thread.join @thread = nil log.info "stopped" end end end |