Module: Async::Service::Supervisor::Supervised
- Defined in:
- lib/async/service/supervisor/supervised.rb
Overview
An environment mixin for supervised worker services.
Enables workers to connect to and be supervised by the supervisor.
Instance Method Summary collapse
-
#prepare!(instance) ⇒ Object
Create a supervised worker for the given instance.
-
#supervisor_endpoint ⇒ Object
The endpoint the supervisor will bind to.
-
#supervisor_ipc_path ⇒ Object
The IPC path to use for communication with the supervisor.
-
#supervisor_worker ⇒ Object
The supervised worker for the current process.
-
#supervisor_worker_state ⇒ Object
The state to associate with the supervised worker.
-
#utilization_registry ⇒ Object
Get the utilization registry for this service.
-
#utilization_schema ⇒ Object
A default schema for utilization metrics.
Instance Method Details
#prepare!(instance) ⇒ Object
Create a supervised worker for the given instance.
74 75 76 77 78 |
# File 'lib/async/service/supervisor/supervised.rb', line 74 def prepare!(instance) super(instance) supervisor_worker.run end |
#supervisor_endpoint ⇒ Object
The endpoint the supervisor will bind to.
26 27 28 |
# File 'lib/async/service/supervisor/supervised.rb', line 26 def supervisor_endpoint ::IO::Endpoint.unix(supervisor_ipc_path) end |
#supervisor_ipc_path ⇒ Object
The IPC path to use for communication with the supervisor.
20 21 22 |
# File 'lib/async/service/supervisor/supervised.rb', line 20 def supervisor_ipc_path ::File.("supervisor.ipc", root) end |
#supervisor_worker ⇒ Object
The supervised worker for the current process.
60 61 62 63 64 65 66 67 68 |
# File 'lib/async/service/supervisor/supervised.rb', line 60 def supervisor_worker Worker.new( process_id: Process.pid, endpoint: supervisor_endpoint, state: self.supervisor_worker_state, utilization_schema: self.utilization_schema, utilization_registry: self.utilization_registry, ) end |
#supervisor_worker_state ⇒ Object
The state to associate with the supervised worker.
32 33 34 |
# File 'lib/async/service/supervisor/supervised.rb', line 32 def supervisor_worker_state {name: self.name} end |
#utilization_registry ⇒ Object
Get the utilization registry for this service.
Creates a new registry instance for tracking utilization metrics. This registry is used by workers to emit metrics that can be collected by the supervisor’s utilization monitor.
54 55 56 |
# File 'lib/async/service/supervisor/supervised.rb', line 54 def utilization_registry Async::Utilization::Registry.new end |
#utilization_schema ⇒ Object
A default schema for utilization metrics.
38 39 40 41 42 43 44 45 |
# File 'lib/async/service/supervisor/supervised.rb', line 38 def utilization_schema { connections_active: :u32, connections_total: :u64, requests_active: :u32, requests_total: :u64, } end |