Class: Falcon::Command::Serve
- Inherits:
-
Samovar::Command
- Object
- Samovar::Command
- Falcon::Command::Serve
- Defined in:
- lib/falcon/command/serve.rb
Overview
Implements the ‘falcon serve` command. Designed for development.
Manages a Controller::Serve instance which is responsible for running applications in a development environment.
Instance Method Summary collapse
-
#call ⇒ Object
Prepare the environment and run the controller.
-
#client ⇒ Object
Create a new client suitable for accessing the application.
-
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
-
#configuration ⇒ Object
Build the service configuration for the serve command.
-
#container_class ⇒ Object
The container class to use.
-
#container_options ⇒ Object
Extract container-related options from the command line options.
-
#endpoint ⇒ Object
The endpoint to bind to.
-
#endpoint_options ⇒ Object
Extract endpoint-related options from the command line options.
-
#environment ⇒ Object
Create the environment for the serve command.
-
#name ⇒ Object
Get the name for the service, using hostname if available, otherwise the bind address.
Instance Method Details
#call ⇒ Object
Prepare the environment and run the controller.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/falcon/command/serve.rb', line 129 def call Console.info(self) do |buffer| buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.}." buffer.puts "- Running on #{RUBY_DESCRIPTION}" 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 |
#client ⇒ Object
Create a new client suitable for accessing the application.
124 125 126 |
# File 'lib/falcon/command/serve.rb', line 124 def client Async::HTTP::Client.new(client_endpoint) end |
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
119 120 121 |
# File 'lib/falcon/command/serve.rb', line 119 def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#configuration ⇒ Object
Build the service configuration for the serve command.
95 96 97 98 99 |
# File 'lib/falcon/command/serve.rb', line 95 def configuration Async::Service::Configuration.new.tap do |configuration| configuration.add(self.environment) end end |
#container_class ⇒ Object
The container class to use.
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/falcon/command/serve.rb', line 102 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 |
#container_options ⇒ Object
Extract container-related options from the command line options.
54 55 56 |
# File 'lib/falcon/command/serve.rb', line 54 def @options.slice(:count, :forks, :threads, :restart, :health_check_timeout) end |
#endpoint ⇒ Object
The endpoint to bind to.
114 115 116 |
# File 'lib/falcon/command/serve.rb', line 114 def endpoint Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
Extract endpoint-related options from the command line options.
60 61 62 |
# File 'lib/falcon/command/serve.rb', line 60 def @options.slice(:hostname, :port, :timeout) end |
#environment ⇒ Object
Create the environment for the serve command.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/falcon/command/serve.rb', line 72 def environment Async::Service::Environment.new(Falcon::Environment::Server).with( Falcon::Environment::Rackup, root: Dir.pwd, verbose: self.parent&.verbose?, cache: @options[:cache], container_options: self., endpoint_options: self., rackup_path: @options[:config], preload: [@options[:preload]].compact, url: @options[:bind], name: self.name, endpoint: ->{Endpoint.parse(url, **)} ) end |
#name ⇒ Object
Get the name for the service, using hostname if available, otherwise the bind address.
66 67 68 |
# File 'lib/falcon/command/serve.rb', line 66 def name @options[:hostname] || @options[:bind] end |