Class: Falcon::Controller::Serve
- Inherits:
-
Async::Container::Controller
- Object
- Async::Container::Controller
- Falcon::Controller::Serve
- Defined in:
- lib/falcon/controller/serve.rb
Instance Method Summary collapse
- #create_container ⇒ Object
- #endpoint ⇒ Object
-
#initialize(command, **options) ⇒ Serve
constructor
A new instance of Serve.
- #load_app ⇒ Object
- #name ⇒ Object
- #setup(container) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(command, **options) ⇒ Serve
Returns a new instance of Serve.
33 34 35 36 37 38 39 40 41 |
# File 'lib/falcon/controller/serve.rb', line 33 def initialize(command, **) @command = command @endpoint = nil @bound_endpoint = nil @debug_trap = Async::IO::Trap.new(:USR1) super(**) end |
Instance Method Details
#create_container ⇒ Object
43 44 45 |
# File 'lib/falcon/controller/serve.rb', line 43 def create_container @command.container_class.new end |
#endpoint ⇒ Object
47 48 49 |
# File 'lib/falcon/controller/serve.rb', line 47 def endpoint @command.endpoint end |
#load_app ⇒ Object
51 52 53 |
# File 'lib/falcon/controller/serve.rb', line 51 def load_app @command.load_app end |
#name ⇒ Object
67 68 69 |
# File 'lib/falcon/controller/serve.rb', line 67 def name "Falcon Server" end |
#setup(container) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/falcon/controller/serve.rb', line 71 def setup(container) container.run(name: self.name, restart: true, **@command.) do |instance| Async do |task| # Load one app instance per container: app = self.load_app task.async do if @debug_trap.install! Async.logger.info(instance) do "- Per-process status: kill -USR1 #{Process.pid}" end end @debug_trap.trap do Async.logger.info(self) do |buffer| task.reactor.print_hierarchy(buffer) end end end server = Falcon::Server.new(app, @bound_endpoint, @endpoint.protocol, @endpoint.scheme) server.run instance.ready! task.children.each(&:wait) end end end |
#start ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/falcon/controller/serve.rb', line 55 def start @endpoint ||= self.endpoint @bound_endpoint = Async::Reactor.run do Async::IO::SharedEndpoint.bound(@endpoint) end.wait @debug_trap.ignore! super end |
#stop ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/falcon/controller/serve.rb', line 102 def stop(*) @bound_endpoint&.close @debug_trap.default! super end |