class Falcon::Command::Serve
def cache?
def cache? @options[:cache] end
def call
def call Async.logger.info(self) do |buffer| buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.container_options}." buffer.puts "- Binding to: #{self.endpoint}" buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}" buffer.puts "- To reload configuration: kill -HUP #{Process.pid}" end if path = @options[:preload] full_path = File.expand_path(path) load(full_path) end Bundler.require(:preload) if GC.respond_to?(:compact) GC.compact end self.controller.run end
def client
def client Async::HTTP::Client.new(client_endpoint) end
def client_endpoint
def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **endpoint_options) end
def container_class
def container_class case @options[:container] when :threaded return Async::Container::Threaded when :forked return Async::Container::Forked when :hybrid return Async::Container::Hybrid end end
def container_options
def container_options slice_options(:count, :forks, :threads) end
def controller
def controller Controller::Serve.new(self) end
def endpoint
def endpoint Endpoint.parse(@options[:bind], **endpoint_options) end
def endpoint_options
def endpoint_options slice_options(:hostname, :port, :reuse_port, :timeout) end
def load_app
def load_app rack_app, _ = Rack::Builder.parse_file(@options[:config]) return Server.middleware(rack_app, verbose: self.verbose?, cache: self.cache?) end
def slice_options(*keys)
def slice_options(*keys) # TODO: Ruby 2.5 introduced Hash#slice options = {} keys.each do |key| if @options.key?(key) options[key] = @options[key] end end return options end
def verbose?
def verbose? @parent&.verbose? end