Skip to main content

ServiceManager

Struct ServiceManager 

Source
pub struct ServiceManager { /* private fields */ }
Expand description

Service manager for multiple services

Implementations§

Source§

impl ServiceManager

Source

pub fn builder(runtime: Arc<dyn Runtime + Send + Sync>) -> ServiceManagerBuilder

Create a ServiceManagerBuilder for constructing a ServiceManager.

This is the preferred way to construct a ServiceManager since v0.2.0.

§Example
let manager = ServiceManager::builder(runtime)
    .overlay_manager(om)
    .proxy_manager(proxy)
    .build();
Source

pub fn new(runtime: Arc<dyn Runtime + Send + Sync>) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Create a new service manager

Source

pub fn with_overlay( runtime: Arc<dyn Runtime + Send + Sync>, overlay_manager: Arc<RwLock<OverlayManager>>, ) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Create a service manager with overlay network support

Source

pub fn with_full_config( runtime: Arc<dyn Runtime + Send + Sync>, overlay_manager: Arc<RwLock<OverlayManager>>, deployment_name: String, ) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Create a fully-configured service manager with overlay and proxy support

Source

pub fn health_states(&self) -> Arc<RwLock<HashMap<String, HealthState>>>

Get the health states map for external monitoring

Source

pub async fn update_health_state(&self, service_name: &str, state: HealthState)

Update health state for a service

Source

pub fn set_deployment_name(&mut self, name: String)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the deployment name (used for generating hostnames)

Source

pub fn set_stream_registry(&mut self, registry: Arc<StreamRegistry>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the stream registry for L4 proxy integration (TCP/UDP)

Source

pub fn with_stream_registry(self, registry: Arc<StreamRegistry>) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Builder pattern: add stream registry for L4 proxy integration

Source

pub fn stream_registry(&self) -> Option<&Arc<StreamRegistry>>

Get the stream registry (if configured)

Source

pub fn set_overlay_manager(&mut self, manager: Arc<RwLock<OverlayManager>>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the overlay manager for container networking

Source

pub fn set_proxy_manager(&mut self, proxy: Arc<ProxyManager>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the proxy manager for health-aware load balancing

Source

pub fn with_proxy_manager(self, proxy: Arc<ProxyManager>) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Builder pattern: add proxy manager for health-aware load balancing

Source

pub fn proxy_manager(&self) -> Option<&Arc<ProxyManager>>

Get the proxy manager (if configured)

Source

pub fn set_dns_server(&mut self, dns: Arc<DnsServer>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the DNS server for service discovery

Source

pub fn with_dns_server(self, dns: Arc<DnsServer>) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Builder pattern: add DNS server for service discovery

Source

pub fn dns_server(&self) -> Option<&Arc<DnsServer>>

Get the DNS server (if configured)

Source

pub fn set_job_executor(&mut self, executor: Arc<JobExecutor>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the job executor for run-to-completion workloads

Source

pub fn set_cron_scheduler(&mut self, scheduler: Arc<CronScheduler>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the cron scheduler for time-based job triggers

Source

pub fn with_job_executor(self, executor: Arc<JobExecutor>) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Builder pattern: add job executor

Source

pub fn with_cron_scheduler(self, scheduler: Arc<CronScheduler>) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Builder pattern: add cron scheduler

Source

pub fn job_executor(&self) -> Option<&Arc<JobExecutor>>

Get the job executor (if configured)

Source

pub fn cron_scheduler(&self) -> Option<&Arc<CronScheduler>>

Get the cron scheduler (if configured)

Source

pub fn set_container_supervisor(&mut self, supervisor: Arc<ContainerSupervisor>)

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Set the container supervisor for crash/panic policy enforcement

Source

pub fn with_container_supervisor( self, supervisor: Arc<ContainerSupervisor>, ) -> Self

👎Deprecated since 0.2.0:

use ServiceManager::builder() instead

Builder pattern: add container supervisor

Source

pub fn container_supervisor(&self) -> Option<&Arc<ContainerSupervisor>>

Get the container supervisor (if configured)

Source

pub fn start_container_supervisor(&self) -> Result<JoinHandle<()>>

Start the container supervisor background task

This spawns a background task that monitors containers for crashes and enforces the on_panic error policy.

§Errors

Returns an error if no container supervisor is configured.

§Returns

A JoinHandle for the supervisor task.

Source

pub fn shutdown_container_supervisor(&self)

Shutdown the container supervisor

Source

pub async fn get_container_supervised_state( &self, container_id: &ContainerId, ) -> Option<SupervisedState>

Get the supervised state of a container

Source

pub async fn take_supervisor_events(&self) -> Option<Receiver<SupervisorEvent>>

Get supervisor events receiver

Note: This can only be called once; the receiver is moved to the caller.

Source

pub async fn deploy_with_dependencies( &self, services: HashMap<String, ServiceSpec>, ) -> Result<()>

Deploy multiple services respecting their dependency order

This method:

  1. Builds a dependency graph from the services
  2. Validates no cycles exist
  3. Computes topological order (services with no deps first)
  4. For each service in order, waits for dependencies then starts the service
§Arguments
  • services - Map of service name to service specification
§Errors
  • Returns AgentError::InvalidSpec if there are cyclic dependencies
  • Returns AgentError::DependencyTimeout if a dependency times out with on_timeout: fail
Source

pub async fn check_dependencies(&self, deps: &[DependsSpec]) -> Result<bool>

Check if all dependencies for a service are currently satisfied

This is a one-shot check (no waiting). Useful for pre-flight validation.

§Errors

Returns an error if a dependency check fails unexpectedly.

Source

pub async fn upsert_service( &self, name: String, spec: ServiceSpec, ) -> Result<()>

Add or update a workload (service, job, or cron)

This method handles different resource types appropriately:

  • Service: Traditional long-running containers with scaling and health checks
  • Job: Run-to-completion workloads triggered on-demand (stores spec for later)
  • Cron: Scheduled run-to-completion workloads (registers with cron scheduler)
§Errors

Returns an error if service creation, scaling, or cron registration fails.

Source

pub async fn scale_service(&self, name: &str, replicas: u32) -> Result<()>

Scale a service to desired replica count

§Errors

Returns an error if the service is not found or scaling fails.

Source

pub async fn service_replica_count(&self, name: &str) -> Result<usize>

Get service replica count

§Errors

Returns an error if the service is not found.

Source

pub async fn remove_service(&self, name: &str) -> Result<()>

Remove a workload (service, job, or cron)

This method handles cleanup for different resource types:

  • Service: Unregisters proxy routes, supervisor, and removes from service map
  • Job: Unregisters from job executor
  • Cron: Unregisters from cron scheduler
§Errors

Returns an error if the service cannot be removed or scale-down fails.

Source

pub async fn service_infrastructure( &self, name: &str, ) -> Option<(bool, bool, bool)>

Introspect service infrastructure wiring. Returns (has_overlay, has_proxy, has_dns), or None if service not found.

Source

pub async fn list_services(&self) -> Vec<String>

List all services

Source

pub async fn get_service_logs( &self, service_name: &str, tail: usize, instance: Option<&str>, ) -> Result<Vec<LogEntry>>

Get logs for a service, aggregated from all container replicas.

§Arguments
  • service_name - Name of the service to fetch logs for
  • tail - Number of lines to return per container (0 = all)
  • instance - Optional specific instance (container ID suffix like “1”, “2”)
§Errors

Returns an error if the service or instance is not found.

§Returns

Structured log entries from all (or specific) container replicas. Each entry has its service and deployment fields populated when available.

Source

pub async fn get_service_containers( &self, service_name: &str, ) -> Vec<ContainerId>

Get all container IDs for a specific service

Returns an empty vector if the service doesn’t exist.

§Arguments
  • service_name - Name of the service to query
§Returns

Vector of ContainerIds for all replicas of the service

Source

pub async fn exec_in_container( &self, service_name: &str, replica: Option<u32>, cmd: &[String], ) -> Result<(i32, String, String)>

Execute a command inside a running container for a service

Picks a specific replica if provided, otherwise uses the first available container.

§Arguments
  • service_name - Name of the service
  • replica - Optional replica number to target
  • cmd - Command and arguments to execute
§Errors

Returns an error if the service or replica is not found, or if exec fails.

§Panics

Panics if no replica is specified and the container list is unexpectedly empty after the emptiness check (should not happen in practice).

§Returns

Tuple of (exit_code, stdout, stderr)

Source

pub async fn trigger_job( &self, name: &str, trigger: JobTrigger, ) -> Result<JobExecutionId>

Trigger a job execution

§Arguments
  • name - Name of the registered job
  • trigger - How the job was triggered (endpoint, cli, etc.)
§Returns

The execution ID for tracking the job

§Errors
  • Returns error if job executor is not configured
  • Returns error if the job is not registered
Source

pub async fn get_job_execution( &self, id: &JobExecutionId, ) -> Option<JobExecution>

Get the status of a job execution

§Arguments
  • id - The execution ID returned from trigger_job
§Returns

The job execution details, or None if not found

Source

pub async fn list_job_executions(&self, name: &str) -> Vec<JobExecution>

List all executions for a specific job

§Arguments
  • name - Name of the job
§Returns

Vector of job executions for the specified job

Source

pub async fn cancel_job(&self, id: &JobExecutionId) -> Result<()>

Cancel a running job execution

§Arguments
  • id - The execution ID to cancel
§Errors

Returns error if job executor is not configured or if cancellation fails

Source

pub async fn trigger_cron(&self, name: &str) -> Result<JobExecutionId>

Manually trigger a cron job (outside of its schedule)

§Arguments
  • name - Name of the cron job
§Returns

The execution ID for tracking the triggered job

§Errors

Returns error if cron scheduler is not configured or job not found

Source

pub async fn set_cron_enabled(&self, name: &str, enabled: bool)

Enable or disable a cron job

§Arguments
  • name - Name of the cron job
  • enabled - Whether to enable or disable the job
Source

pub async fn list_cron_jobs(&self) -> Vec<CronJobInfo>

List all registered cron jobs

Source

pub fn start_cron_scheduler(&self) -> Result<JoinHandle<()>>

Start the cron scheduler background task

This spawns a background task that checks for due cron jobs every second. Returns a JoinHandle that can be used to wait for the scheduler to stop.

§Errors

Returns error if cron scheduler is not configured

Source

pub fn shutdown_cron(&self)

Shutdown the cron scheduler

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ServiceExt for T

Source§

fn propagate_header(self, header: HeaderName) -> PropagateHeader<Self>
where Self: Sized,

Propagate a header from the request to the response. Read more
Source§

fn add_extension<T>(self, value: T) -> AddExtension<Self, T>
where Self: Sized,

Add some shareable value to request extensions. Read more
Source§

fn map_request_body<F>(self, f: F) -> MapRequestBody<Self, F>
where Self: Sized,

Apply a transformation to the request body. Read more
Source§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
Source§

fn compression(self) -> Compression<Self>
where Self: Sized,

Compresses response bodies. Read more
Source§

fn decompression(self) -> Decompression<Self>
where Self: Sized,

Decompress response bodies. Read more
Source§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
Source§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
Source§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

fn sensitive_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>
where Self: Sized,

Mark headers as sensitive on both requests and responses. Read more
Source§

fn sensitive_request_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveRequestHeaders<Self>
where Self: Sized,

Mark headers as sensitive on requests. Read more
Source§

fn sensitive_response_headers( self, headers: impl IntoIterator<Item = HeaderName>, ) -> SetSensitiveResponseHeaders<Self>
where Self: Sized,

Mark headers as sensitive on responses. Read more
Source§

fn override_request_header<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Insert a header into the request. Read more
Source§

fn append_request_header<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Append a header into the request. Read more
Source§

fn insert_request_header_if_not_present<M>( self, header_name: HeaderName, make: M, ) -> SetRequestHeader<Self, M>
where Self: Sized,

Insert a header into the request, if the header is not already present. Read more
Source§

fn override_response_header<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Insert a header into the response. Read more
Source§

fn append_response_header<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Append a header into the response. Read more
Source§

fn insert_response_header_if_not_present<M>( self, header_name: HeaderName, make: M, ) -> SetResponseHeader<Self, M>
where Self: Sized,

Insert a header into the response, if the header is not already present. Read more
Source§

fn set_request_id<M>( self, header_name: HeaderName, make_request_id: M, ) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Add request id header and extension. Read more
Source§

fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>
where Self: Sized, M: MakeRequestId,

Add request id header and extension, using x-request-id as the header name. Read more
Source§

fn propagate_request_id( self, header_name: HeaderName, ) -> PropagateRequestId<Self>
where Self: Sized,

Propgate request ids from requests to responses. Read more
Source§

fn propagate_x_request_id(self) -> PropagateRequestId<Self>
where Self: Sized,

Propgate request ids from requests to responses, using x-request-id as the header name. Read more
Source§

fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>
where Self: Sized,

Catch panics and convert them into 500 Internal Server responses. Read more
Source§

fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>
where Self: Sized,

Intercept requests with over-sized payloads and convert them into 413 Payload Too Large responses. Read more
Source§

fn trim_trailing_slash(self) -> NormalizePath<Self>
where Self: Sized,

Remove trailing slashes from paths. Read more
Source§

fn append_trailing_slash(self) -> NormalizePath<Self>
where Self: Sized,

Append trailing slash to paths. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> OptionalSend for T
where T: Send + ?Sized,

Source§

impl<T> OptionalSync for T
where T: Sync + ?Sized,