Class: Falcon::Service::Server
- Inherits:
-
Async::Service::Generic
- Object
- Async::Service::Generic
- Falcon::Service::Server
- Defined in:
- lib/falcon/service/server.rb
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
-
#preload! ⇒ Object
Preload any resources specified by the environment.
-
#setup(container) ⇒ Object
Setup the container with the application instance.
-
#start ⇒ Object
Prepare the bound endpoint for the server.
-
#stop ⇒ Object
Close the bound endpoint.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
16 17 18 19 20 |
# File 'lib/falcon/service/server.rb', line 16 def initialize(...) super @bound_endpoint = nil end |
Instance Method Details
#preload! ⇒ Object
Preload any resources specified by the environment.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/falcon/service/server.rb', line 23 def preload! root = @evaluator.root if scripts = @evaluator.preload scripts = Array(scripts) scripts.each do |path| Console.logger.info(self) {"Preloading #{path}..."} full_path = File.(path, root) load(full_path) end end end |
#setup(container) ⇒ Object
Setup the container with the application instance.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/falcon/service/server.rb', line 54 def setup(container) = @evaluator. health_check_timeout = [:health_check_timeout] container.run(name: self.name, **) do |instance| evaluator = @environment.evaluator Async do |task| if @environment.implements?(Async::Container::Supervisor::Supervised) evaluator.make_supervised_worker(instance).run end server = evaluator.make_server(@bound_endpoint) server.run instance.ready! if health_check_timeout Async(transient: true) do while true # We only update this if the health check is enabled. Maybe we should always update it? instance.name = "#{self.name} (#{server.statistics_string} L=#{Fiber.scheduler.load.round(3)})" sleep(health_check_timeout / 2) instance.ready! end end end task.children.each(&:wait) end end end |
#start ⇒ Object
Prepare the bound endpoint for the server.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/falcon/service/server.rb', line 38 def start @endpoint = @evaluator.endpoint Sync do @bound_endpoint = @endpoint.bound end preload! Console.logger.info(self) {"Starting #{self.name} on #{@endpoint}"} super end |
#stop ⇒ Object
Close the bound endpoint.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/falcon/service/server.rb', line 89 def stop(...) if @bound_endpoint @bound_endpoint.close @bound_endpoint = nil end @endpoint = nil super end |