pub struct JanusSupervisor { /* private fields */ }Expand description
The central supervisor for the Janus system.
Manages the lifecycle of all JanusService implementations using
TaskTracker for structured concurrency and CancellationToken
for graceful shutdown propagation.
§Memory Safety
Unlike JoinSet, TaskTracker does not accumulate task return
values. Completed task memory is reclaimed immediately, making this
safe for long-running processes that may restart services hundreds of
times over weeks of operation.
Implementations§
Source§impl JanusSupervisor
impl JanusSupervisor
Sourcepub fn new(config: SupervisorConfig) -> Self
pub fn new(config: SupervisorConfig) -> Self
Create a new supervisor with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new supervisor with default configuration.
Sourcepub fn cancel_token(&self) -> &CancellationToken
pub fn cancel_token(&self) -> &CancellationToken
Get a reference to the supervisor’s cancellation token.
Useful for external code that needs to observe or trigger shutdown.
Sourcepub fn metrics(&self) -> &Arc<SupervisorMetrics>
pub fn metrics(&self) -> &Arc<SupervisorMetrics>
Get a reference to the supervisor’s metrics.
Sourcepub async fn lifecycle_snapshots(&self) -> Vec<ServiceLifecycleSnapshot>
pub async fn lifecycle_snapshots(&self) -> Vec<ServiceLifecycleSnapshot>
Get a snapshot of all service lifecycles.
Sourcepub async fn service_lifecycle(
&self,
name: &str,
) -> Option<ServiceLifecycleSnapshot>
pub async fn service_lifecycle( &self, name: &str, ) -> Option<ServiceLifecycleSnapshot>
Get the lifecycle snapshot for a specific service by name.
Sourcepub async fn service_count(&self) -> usize
pub async fn service_count(&self) -> usize
Number of services currently tracked (alive + terminated).
Sourcepub fn trigger_shutdown(&self)
pub fn trigger_shutdown(&self)
Trigger a graceful shutdown of all managed services.
This cancels the root cancellation token, which propagates to all
child tokens held by running services. The supervisor’s
run_until_shutdown (or wait_for_drain) will then wait for
tasks to complete up to the configured timeout.
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Returns true if the supervisor’s shutdown has been triggered.
Sourcepub fn spawn_service(&self, service: Box<dyn JanusService>)
pub fn spawn_service(&self, service: Box<dyn JanusService>)
Spawn a service into the supervisor with default options.
The service will be wrapped in a restart loop governed by its
RestartPolicy and the supervisor’s default BackoffConfig.
Sourcepub fn spawn_service_with_options(
&self,
service: Box<dyn JanusService>,
options: SpawnOptions,
)
pub fn spawn_service_with_options( &self, service: Box<dyn JanusService>, options: SpawnOptions, )
Spawn a service with custom per-service options.
Sourcepub async fn wait_for_drain(&self)
pub async fn wait_for_drain(&self)
Close the tracker and wait for all tasks to complete, with timeout.
Call this after triggering shutdown (or after run_until_shutdown
returns) to ensure all tasks have drained.
Sourcepub async fn run_until_shutdown(&self) -> Result<()>
pub async fn run_until_shutdown(&self) -> Result<()>
Run the supervisor until a shutdown signal is received.
If install_signal_handler is true in the config (the default),
this will listen for Ctrl+C / SIGTERM and trigger shutdown.
Returns after all services have drained (or the shutdown timeout has elapsed).