Class: Falcon::Command::Serve

Inherits:
Samovar::Command
  • Object
show all
Defined in:
lib/falcon/command/serve.rb

Instance Method Summary collapse

Instance Method Details

#callObject



120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/falcon/command/serve.rb', line 120

def call
  Async.logger.info(self.endpoint) do |buffer|
    buffer.puts "Falcon v#{VERSION} taking flight! Using #{self.container_class} #{self.container_options}."
    buffer.puts "- To terminate: Ctrl-C or kill #{Process.pid}"
    buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
  end
  
  if @options[:preload]
    Bundler.require(:preload)
  end
  
  self.controller.run
end

#clientObject



112
113
114
# File 'lib/falcon/command/serve.rb', line 112

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

#client_endpointObject



108
109
110
# File 'lib/falcon/command/serve.rb', line 108

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

#container_classObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/falcon/command/serve.rb', line 62

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_optionsObject



96
97
98
# File 'lib/falcon/command/serve.rb', line 96

def container_options
  slice_options(:count, :forks, :threads)
end

#controllerObject



116
117
118
# File 'lib/falcon/command/serve.rb', line 116

def controller
  Controller::Serve.new(self)
end

#endpointObject



104
105
106
# File 'lib/falcon/command/serve.rb', line 104

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

#endpoint_optionsObject



100
101
102
# File 'lib/falcon/command/serve.rb', line 100

def endpoint_options
  slice_options(:hostname, :port, :reuse_port, :timeout)
end

#load_app(verbose = self.verbose?) ⇒ Object



77
78
79
80
81
# File 'lib/falcon/command/serve.rb', line 77

def load_app(verbose = self.verbose?)
  rack_app, options = Rack::Builder.parse_file(@options[:config])
  
  return Server.middleware(rack_app, verbose: verbose), options
end

#slice_options(*keys) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/falcon/command/serve.rb', line 83

def slice_options(*keys)
  # TODO: Ruby 2.5 introduced Hash#slice
  options = {}
  
  keys.each do |key|
    if @options.key?(key)
      options[key] = @options[key]
    end
  end
  
  return options
end

#verbose?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/falcon/command/serve.rb', line 73

def verbose?
  @parent&.verbose?
end