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
-
#container_class ⇒ Object
The container class to use.
- #container_options ⇒ Object
-
#endpoint ⇒ Object
The endpoint to bind to.
- #endpoint_options ⇒ Object
- #environment ⇒ Object
Instance Method Details
#call ⇒ Object
Prepare the environment and run the controller.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/falcon/command/serve.rb', line 111 def call Console.logger.info(self) do |buffer| buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.}." 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) end |
#client ⇒ Object
Create a new client suitable for accessing the application.
106 107 108 |
# File 'lib/falcon/command/serve.rb', line 106 def client Async::HTTP::Client.new(client_endpoint) end |
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
101 102 103 |
# File 'lib/falcon/command/serve.rb', line 101 def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#configuration ⇒ Object
77 78 79 80 81 |
# File 'lib/falcon/command/serve.rb', line 77 def configuration Configuration.new.tap do |configuration| configuration.add(self.environment) end end |
#container_class ⇒ Object
The container class to use.
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/falcon/command/serve.rb', line 84 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
47 48 49 |
# File 'lib/falcon/command/serve.rb', line 47 def @options.slice(:count, :forks, :threads) end |
#endpoint ⇒ Object
The endpoint to bind to.
96 97 98 |
# File 'lib/falcon/command/serve.rb', line 96 def endpoint Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
51 52 53 |
# File 'lib/falcon/command/serve.rb', line 51 def @options.slice(:hostname, :port, :timeout) end |
#environment ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/falcon/command/serve.rb', line 55 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: "server", endpoint: ->{Endpoint.parse(url, **)} ) end |