Add worker support (experimental)
This commit is contained in:
parent
d825b2316a
commit
a67a8508cf
4 changed files with 14 additions and 4 deletions
13
src/kemal.cr
13
src/kemal.cr
|
@ -9,6 +9,9 @@ at_exit do
|
||||||
opts.on("-e ", "--environment ", "environment") do |env|
|
opts.on("-e ", "--environment ", "environment") do |env|
|
||||||
Kemal.config.env = env
|
Kemal.config.env = env
|
||||||
end
|
end
|
||||||
|
opts.on("-w VALUE", "--workers", "workers") do |workers|
|
||||||
|
Kemal.config.workers = workers.to_i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config = Kemal.config
|
config = Kemal.config
|
||||||
|
@ -17,7 +20,7 @@ at_exit do
|
||||||
config.add_handler Kemal::Handler::INSTANCE
|
config.add_handler Kemal::Handler::INSTANCE
|
||||||
config.add_handler HTTP::StaticFileHandler.new("./public")
|
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
|
server.ssl = config.ssl
|
||||||
logger.write "[#{config.env}] Kemal is ready to lead at #{config.scheme}://0.0.0.0:#{config.port}\n"
|
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)
|
File.read(file_path)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -5,10 +5,12 @@ module Kemal
|
||||||
property ssl
|
property ssl
|
||||||
property port
|
property port
|
||||||
property env
|
property env
|
||||||
|
property workers
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@port = 3000
|
@port = 3000
|
||||||
@env = "development" unless @env
|
@env = "development" unless @env
|
||||||
|
@workers = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def scheme
|
def scheme
|
||||||
|
|
|
@ -11,7 +11,6 @@ class Kemal::Route
|
||||||
|
|
||||||
def match?(request)
|
def match?(request)
|
||||||
check_for_method_override!(request)
|
check_for_method_override!(request)
|
||||||
|
|
||||||
return nil unless request.override_method == @method
|
return nil unless request.override_method == @method
|
||||||
components = request.path.not_nil!.split "/"
|
components = request.path.not_nil!.split "/"
|
||||||
return nil unless components.size == @components.size
|
return nil unless components.size == @components.size
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Kemal render uses built-in ECR to render methods.
|
# Kemal render uses built-in ECR to render methods.
|
||||||
|
|
||||||
## Usage
|
# # Usage
|
||||||
# get '/' do
|
# get '/' do
|
||||||
# render 'hello.ecr'
|
# render 'hello.ecr'
|
||||||
# end
|
# end
|
||||||
|
|
Loading…
Reference in a new issue