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.
Class Method Summary collapse
-
.for(*services, **options) ⇒ Object
Create a controller for the given services.
-
.run(configuration, **options) ⇒ Object
Run a configuration of services.
-
.warmup ⇒ Object
Warm up the Ruby process by preloading gems and running GC.
Instance Method Summary collapse
-
#initialize(services, **options) ⇒ Controller
constructor
Initialize a new controller with services.
- #services ⇒ Object
-
#setup(container) ⇒ Object
Setup all services into the given container.
-
#start ⇒ Object
Start all named services.
-
#stop(graceful = true) ⇒ Object
Stop all named services.
Constructor Details
#initialize(services, **options) ⇒ Controller
Initialize a new controller with services.
55 56 57 58 59 |
# File 'lib/async/service/controller.rb', line 55 def initialize(services, **) super(**) @services = services end |
Class Method Details
.for(*services, **options) ⇒ Object
Create a controller for the given services.
48 49 50 |
# File 'lib/async/service/controller.rb', line 48 def self.for(*services, **) self.new(services, **) end |
.run(configuration, **options) ⇒ Object
Run a configuration of services.
36 37 38 39 40 41 42 |
# File 'lib/async/service/controller.rb', line 36 def self.run(configuration, **) controller = Async::Service::Controller.new(configuration.services.to_a, **) self.warmup controller.run end |
.warmup ⇒ Object
Warm up the Ruby process by preloading gems and running GC.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/async/service/controller.rb', line 17 def self.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 |
Instance Method Details
#services ⇒ Object
63 64 65 |
# File 'lib/async/service/controller.rb', line 63 def services @services end |
#setup(container) ⇒ Object
Setup all services into the given container.
77 78 79 80 81 82 83 84 85 |
# File 'lib/async/service/controller.rb', line 77 def setup(container) super @services.each do |service| service.setup(container) end return container end |
#start ⇒ Object
Start all named services.
66 67 68 69 70 71 72 |
# File 'lib/async/service/controller.rb', line 66 def start @services.each do |service| service.start end super end |
#stop(graceful = true) ⇒ Object
Stop all named services.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/async/service/controller.rb', line 88 def stop(graceful = true) @services.each do |service| begin service.stop rescue => error Console.error(self, error) end end super end |