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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/falcon/controller/serve.rb', line 31 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
41 42 43 |
# File 'lib/falcon/controller/serve.rb', line 41 def create_container @command.container_class.new end |
#endpoint ⇒ Object
45 46 47 |
# File 'lib/falcon/controller/serve.rb', line 45 def endpoint @command.endpoint end |
#load_app ⇒ Object
49 50 51 |
# File 'lib/falcon/controller/serve.rb', line 49 def load_app @command.load_app end |
#name ⇒ Object
65 66 67 |
# File 'lib/falcon/controller/serve.rb', line 65 def name "Falcon Server" end |
#setup(container) ⇒ Object
69 70 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 101 |
# File 'lib/falcon/controller/serve.rb', line 69 def setup(container) app, _ = self.load_app if GC.respond_to?(:compact) GC.compact end container.run(name: self.name, restart: true, **@command.) do |instance| Async do |task| 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
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/falcon/controller/serve.rb', line 53 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
103 104 105 106 107 108 109 |
# File 'lib/falcon/controller/serve.rb', line 103 def stop(*) @bound_endpoint&.close @debug_trap.default! super end |