Add worker support (experimental)

This commit is contained in:
Sdogruyol 2015-12-08 22:15:13 +02:00
parent d825b2316a
commit a67a8508cf
4 changed files with 14 additions and 4 deletions

View File

@ -9,6 +9,9 @@ at_exit do
opts.on("-e ", "--environment ", "environment") do |env|
Kemal.config.env = env
end
opts.on("-w VALUE", "--workers", "workers") do |workers|
Kemal.config.workers = workers.to_i
end
end
config = Kemal.config
@ -17,7 +20,7 @@ at_exit do
config.add_handler Kemal::Handler::INSTANCE
config.add_handler HTTP::StaticFileHandler.new("./public")
server = HTTP::Server.new("0.0.0.0", config.port, config.handlers)
server = HTTP::Server.new(config.port, config.handlers)
server.ssl = config.ssl
logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://0.0.0.0:#{config.port}\n"
@ -37,5 +40,11 @@ at_exit do
File.read(file_path)
end
server.listen
workers = Kemal.config.workers
if workers > 1
logger.write "Kemal is starting with #{workers} workers!"
server.listen_fork workers: workers
else
server.listen
end
end

View File

@ -5,10 +5,12 @@ module Kemal
property ssl
property port
property env
property workers
def initialize
@port = 3000
@env = "development" unless @env
@workers = 1
end
def scheme

View File

@ -11,7 +11,6 @@ class Kemal::Route
def match?(request)
check_for_method_override!(request)
return nil unless request.override_method == @method
components = request.path.not_nil!.split "/"
return nil unless components.size == @components.size

View File

@ -1,6 +1,6 @@
# Kemal render uses built-in ECR to render methods.
## Usage
# # Usage
# get '/' do
# render 'hello.ecr'
# end