Skip to main content

Module adapters

Module adapters 

Source
Expand description

Service adapters for integrating existing Janus modules with the JanusSupervisor.

The existing Janus services (Forward, Backward, CNS, Data) expose a start_module(state: Arc<JanusState>) -> Result<()> entry point that internally polls state.is_shutdown_requested() for lifecycle control.

The supervisor, however, manages services through the JanusService trait which passes a CancellationToken for shutdown signalling.

This module provides ModuleAdapter — a bridge that:

  1. Wraps any start_module-style async function into a JanusService
  2. Bridges the supervisor’s CancellationTokenJanusState::request_shutdown()
  3. Propagates errors back to the supervisor for restart decisions

§Example

use janus_core::supervisor::adapters::ModuleAdapter;
use janus_core::supervisor::RestartPolicy;

let data_adapter = ModuleAdapter::new(
    "data",
    state.clone(),
    |s| Box::pin(janus_data::start_module(s)),
    RestartPolicy::OnFailure,
);

supervisor.spawn_service(Box::new(data_adapter));

Structs§

ApiModuleAdapter
A convenience wrapper for the API module which is always started immediately (it doesn’t wait for start_services()) and should always be restarted on failure.
ModuleAdapter
Adapts an existing start_module(Arc<JanusState>) -> Result<()> function into a JanusService that the supervisor can manage.

Type Aliases§

ModuleStartFn
A boxed async function that takes Arc<JanusState> and returns a Result.