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
- #name ⇒ Object
Instance Method Details
#call ⇒ Object
Prepare the environment and run the controller.
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/falcon/command/serve.rb', line 120 def call Console.logger.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.
115 116 117 |
# File 'lib/falcon/command/serve.rb', line 115 def client Async::HTTP::Client.new(client_endpoint) end |
#client_endpoint ⇒ Object
The endpoint suitable for a client to connect.
110 111 112 |
# File 'lib/falcon/command/serve.rb', line 110 def client_endpoint Async::HTTP::Endpoint.parse(@options[:bind], **) end |
#configuration ⇒ Object
86 87 88 89 90 |
# File 'lib/falcon/command/serve.rb', line 86 def configuration Configuration.new.tap do |configuration| configuration.add(self.environment) end end |
#container_class ⇒ Object
The container class to use.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/falcon/command/serve.rb', line 93 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
52 53 54 |
# File 'lib/falcon/command/serve.rb', line 52 def @options.slice(:count, :forks, :threads, :restart, :health_check_timeout) end |
#endpoint ⇒ Object
The endpoint to bind to.
105 106 107 |
# File 'lib/falcon/command/serve.rb', line 105 def endpoint Endpoint.parse(@options[:bind], **) end |
#endpoint_options ⇒ Object
56 57 58 |
# File 'lib/falcon/command/serve.rb', line 56 def @options.slice(:hostname, :port, :timeout) end |
#environment ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/falcon/command/serve.rb', line 64 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
60 61 62 |
# File 'lib/falcon/command/serve.rb', line 60 def name @options[:hostname] || @options[:bind] end |