Falcon SourceFalconCommandServe

class Serve

Implements the falcon serve command. Designed for development.

Manages a Controller::Serve instance which is responsible for running applications in a development environment.

Definitions

options { ... }

The command line options.

Signature

attribute Samovar::Options

Implementation

options do
	option '-b/--bind <address>', "Bind to the given hostname/address.", default: "https://localhost:9292"
	
	option '-p/--port <number>', "Override the specified port.", type: Integer
	option '-h/--hostname <hostname>', "Specify the hostname which would be used for certificates, etc."
	option '-t/--timeout <duration>', "Specify the maximum time to wait for non-blocking operations.", type: Float, default: nil
	
	option '-c/--config <path>', "Rackup configuration file to load.", default: 'config.ru'
	option '--preload <path>', "Preload the specified path before creating containers."
	
	option '--cache', "Enable the response cache."
	
	option '--forked | --threaded | --hybrid', "Select a specific parallelism model.", key: :container, default: :forked
	
	option '-n/--count <count>', "Number of instances to start.", default: Async::Container.processor_count, type: Integer
	
	option '--forks <count>', "Number of forks (hybrid only).", type: Integer
	option '--threads <count>', "Number of threads (hybrid only).", type: Integer
	
	option '--[no]-restart', "Enable/disable automatic restart.", default: true
	option '--graceful-stop <timeout>', "Duration to wait for graceful stop.", type: Float, default: 1.0
end

def container_class

The container class to use.

Implementation

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 endpoint

The endpoint to bind to.

Implementation

def endpoint
	Endpoint.parse(@options[:bind], **endpoint_options)
end

def client_endpoint

The endpoint suitable for a client to connect.

Implementation

def client_endpoint
	Async::HTTP::Endpoint.parse(@options[:bind], **endpoint_options)
end

def client

Create a new client suitable for accessing the application.

Implementation

def client
	Async::HTTP::Client.new(client_endpoint)
end

def call

Prepare the environment and run the controller.

Implementation

def call
	Console.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
	
	Async::Service::Controller.run(self.configuration, container_class: self.container_class, graceful_stop: @options[:graceful_stop])
end