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.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/falcon/command/serve.rb', line 114 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, graceful_stop: @options[:graceful_stop]) end |
#client ⇒ Object
Create a new client suitable for accessing the application.
109 110 111 |
# File 'lib/falcon/command/serve.rb', line 109 def client Async::HTTP::Client.new(client_endpoint) end |
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
104 105 106 |
# File 'lib/falcon/command/serve.rb', line 104 def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#configuration ⇒ Object
80 81 82 83 84 |
# File 'lib/falcon/command/serve.rb', line 80 def configuration Configuration.new.tap do |configuration| configuration.add(self.environment) end end |
#container_class ⇒ Object
The container class to use.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/falcon/command/serve.rb', line 87 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
50 51 52 |
# File 'lib/falcon/command/serve.rb', line 50 def @options.slice(:count, :forks, :threads, :restart) end |
#endpoint ⇒ Object
The endpoint to bind to.
99 100 101 |
# File 'lib/falcon/command/serve.rb', line 99 def endpoint Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
54 55 56 |
# File 'lib/falcon/command/serve.rb', line 54 def @options.slice(:hostname, :port, :timeout) end |
#environment ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/falcon/command/serve.rb', line 58 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 |