Class: Async::Service::Controller
- Inherits:
-
Container::Controller
- Object
- Container::Controller
- Async::Service::Controller
- Defined in:
- lib/async/service/controller.rb
Overview
Controls multiple services and their lifecycle.
The controller manages starting, stopping, and monitoring multiple services within containers. It extends Async::Container::Controller to provide service-specific functionality.
Instance Attribute Summary collapse
-
#services ⇒ Object
readonly
All the services associated with this controller.
Class Method Summary collapse
-
.for(*services, **options) ⇒ Object
Create a controller for the given services.
-
.run(configuration, **options) ⇒ Object
Run a configuration of services.
Instance Method Summary collapse
-
#initialize(services, **options) ⇒ Controller
constructor
Initialize a new controller with services.
-
#make_policy ⇒ Object
Create a policy for managing child lifecycle events.
-
#setup(container) ⇒ Object
Setup all services into the given container.
-
#start ⇒ Object
Start all named services.
-
#stop(graceful = true) ⇒ Object
Stop all named services.
-
#warmup ⇒ Object
Warm up the Ruby process by preloading gems, running GC, and compacting memory.
Constructor Details
#initialize(services, **options) ⇒ Controller
Initialize a new controller with services.
35 36 37 38 39 |
# File 'lib/async/service/controller.rb', line 35 def initialize(services, **) super(**) @services = services end |
Instance Attribute Details
#services ⇒ Object (readonly)
All the services associated with this controller.
61 62 63 |
# File 'lib/async/service/controller.rb', line 61 def services @services end |
Class Method Details
.for(*services, **options) ⇒ Object
Create a controller for the given services.
28 29 30 |
# File 'lib/async/service/controller.rb', line 28 def self.for(*services, **) self.new(services, **) end |
.run(configuration, **options) ⇒ Object
Run a configuration of services.
20 21 22 |
# File 'lib/async/service/controller.rb', line 20 def self.run(configuration, **) configuration.make_controller(**).run end |
Instance Method Details
#make_policy ⇒ Object
Create a policy for managing child lifecycle events.
65 66 67 |
# File 'lib/async/service/controller.rb', line 65 def make_policy Policy::DEFAULT end |
#setup(container) ⇒ Object
Setup all services into the given container.
83 84 85 86 87 88 89 90 91 |
# File 'lib/async/service/controller.rb', line 83 def setup(container) super @services.each do |service| service.setup(container) end return container end |
#start ⇒ Object
Start all named services.
70 71 72 73 74 75 76 77 78 |
# File 'lib/async/service/controller.rb', line 70 def start @services.each do |service| service.start end super self.warmup end |
#stop(graceful = true) ⇒ Object
Stop all named services.
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/async/service/controller.rb', line 94 def stop(graceful = true) @services.each do |service| begin service.stop rescue => error Console.error(self, error) end end super end |
#warmup ⇒ Object
Warm up the Ruby process by preloading gems, running GC, and compacting memory. This reduces startup latency and improves copy-on-write efficiency.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/async/service/controller.rb', line 43 def warmup begin require "bundler" Bundler.require(:preload) rescue Bundler::GemfileNotFound, LoadError # Ignore. end if ::Process.respond_to?(:warmup) ::Process.warmup elsif ::GC.respond_to?(:compact) 3.times{::GC.start} ::GC.compact end end |