module Supervised
An environment mixin for supervised worker services.
Enables workers to connect to and be supervised by the supervisor.
Definitions
def supervisor_ipc_path
The IPC path to use for communication with the supervisor.
Signature
-
returns
String
Implementation
def supervisor_ipc_path
::File.expand_path("supervisor.ipc", root)
end
def supervisor_endpoint
The endpoint the supervisor will bind to.
Signature
-
returns
::IO::Endpoint::Generic
Implementation
def supervisor_endpoint
::IO::Endpoint.unix(supervisor_ipc_path)
end
def supervisor_worker_state
The state to associate with the supervised worker.
Signature
-
returns
Hash
Implementation
def supervisor_worker_state
{name: self.name}
end
def utilization_schema
A default schema for utilization metrics.
Signature
-
returns
Hash | Nil The utilization schema or nil if utilization is disabled.
Implementation
def utilization_schema
{
connections_active: :u32,
connections_total: :u64,
requests_active: :u32,
requests_total: :u64,
}
end
def utilization_registry
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.
Signature
-
returns
Async::Utilization::Registry A new utilization registry instance.
Implementation
def utilization_registry
Async::Utilization::Registry.new
end
def supervisor_worker
The supervised worker for the current process.
Signature
-
returns
Worker The worker client.
Implementation
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
def prepare!(instance)
Create a supervised worker for the given instance.
Signature
-
parameter
instanceAsync::Container::Instance The container instance.
-
returns
Worker The worker client.
Implementation
def prepare!(instance)
super(instance)
supervisor_worker.run
end