pub struct SupervisorHandle { /* private fields */ }Expand description
Cloneable handle used to control a running supervisor.
Implementations§
Source§impl SupervisorHandle
impl SupervisorHandle
Sourcepub fn new(
command_sender: Sender<RuntimeLoopMessage>,
event_sender: Sender<String>,
control_plane: RuntimeControlPlane,
) -> Self
pub fn new( command_sender: Sender<RuntimeLoopMessage>, event_sender: Sender<String>, control_plane: RuntimeControlPlane, ) -> Self
Creates a runtime handle from channel senders.
§Arguments
command_sender: Sender used to submit runtime commands.event_sender: Sender used to subscribe to lifecycle events.
§Returns
Returns a SupervisorHandle.
Sourcepub async fn add_child(
&self,
target: SupervisorPath,
child_manifest: impl Into<String>,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn add_child( &self, target: SupervisorPath, child_manifest: impl Into<String>, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Adds a child manifest under a supervisor path.
§Arguments
target: Supervisor path that should receive the child.child_manifest: Child manifest text supplied by the caller.requested_by: Caller that requested the command.reason: Human-readable command reason.
§Child Manifest Example
The runtime expects a YAML child declaration. The smallest useful manifest names the child and selects a task kind:
name: worker
kind: async_workerOptional fields can be added when the child needs dependencies, lifecycle policy, resource limits, command permissions, environment variables, or secret references:
name: worker
kind: async_worker
criticality: optional
restart_policy: transient
dependencies:
- cache
health_check:
check_interval_secs: 10
timeout_secs: 5
max_retries: 3
readiness:
check_interval_secs: 5
timeout_secs: 3
resource_limits:
max_memory_mb: 256
max_cpu_percent: 80
max_file_descriptors: 1024
command_permissions:
allow_shutdown: false
allow_restart: true
allowed_signals:
- SIGTERM
environment:
- name: WORKER_MODE
value: queue
- name: API_TOKEN
secret_ref: ${API_TOKEN}
secrets:
- name: API_TOKEN
key: workers/api_token
required: true§Example
use rust_supervisor::control::command::CommandResult;
use rust_supervisor::id::types::SupervisorPath;
use rust_supervisor::runtime::supervisor::Supervisor;
use rust_supervisor::spec::supervisor::SupervisorSpec;
let handle = Supervisor::start(SupervisorSpec::root(Vec::new())).await?;
let result = handle
.add_child(
SupervisorPath::root(),
"name: worker\nkind: async_worker\n",
"operator",
"attach worker during runtime update",
)
.await?;
assert!(matches!(result, CommandResult::ChildAdded { .. }));§Returns
Returns a CommandResult after the runtime accepts the command.
Sourcepub async fn remove_child(
&self,
child_id: ChildId,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn remove_child( &self, child_id: ChildId, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Removes a child from runtime governance.
§Arguments
child_id: Target child identifier.requested_by: Caller that requested the command.reason: Human-readable command reason.
§Returns
Returns a CommandResult after removal or idempotent reuse.
Sourcepub async fn restart_child(
&self,
child_id: ChildId,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn restart_child( &self, child_id: ChildId, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Restarts a child explicitly.
§Arguments
child_id: Target child identifier.requested_by: Caller that requested the command.reason: Human-readable command reason.
§Returns
Returns a CommandResult after restart dispatch.
Sourcepub async fn pause_child(
&self,
child_id: ChildId,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn pause_child( &self, child_id: ChildId, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Sourcepub async fn resume_child(
&self,
child_id: ChildId,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn resume_child( &self, child_id: ChildId, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Sourcepub async fn quarantine_child(
&self,
child_id: ChildId,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn quarantine_child( &self, child_id: ChildId, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Sourcepub async fn shutdown_tree(
&self,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<CommandResult, SupervisorError>
pub async fn shutdown_tree( &self, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<CommandResult, SupervisorError>
Sourcepub async fn current_state(&self) -> Result<CommandResult, SupervisorError>
pub async fn current_state(&self) -> Result<CommandResult, SupervisorError>
Queries the current runtime state.
§Arguments
This function has no arguments.
§Returns
Returns a CommandResult::CurrentState value.
Sourcepub fn health(&self) -> RuntimeHealthReport
pub fn health(&self) -> RuntimeHealthReport
Returns a runtime control plane health report.
§Arguments
This function has no arguments.
§Returns
Returns a RuntimeHealthReport value for the current observation.
Sourcepub async fn join(&self) -> Result<RuntimeExitReport, SupervisorError>
pub async fn join(&self) -> Result<RuntimeExitReport, SupervisorError>
Waits until the runtime control plane reaches a final state.
§Arguments
This function has no arguments.
§Returns
Returns the cached RuntimeExitReport.
Sourcepub async fn shutdown(
&self,
requested_by: impl Into<String>,
reason: impl Into<String>,
) -> Result<RuntimeExitReport, SupervisorError>
pub async fn shutdown( &self, requested_by: impl Into<String>, reason: impl Into<String>, ) -> Result<RuntimeExitReport, SupervisorError>
Requests shutdown for the runtime control plane itself.
§Arguments
requested_by: Caller that requested shutdown.reason: Human-readable shutdown reason.
§Returns
Returns the final RuntimeExitReport.
Sourcepub fn subscribe_events(&self) -> Receiver<String>
pub fn subscribe_events(&self) -> Receiver<String>
Sourcepub fn observability_recorder(&self) -> TestRecorder
pub fn observability_recorder(&self) -> TestRecorder
Returns a copy of the typed observability test recorder.
§Arguments
This function has no arguments.
§Returns
Returns the currently retained TestRecorder contents.
Trait Implementations§
Source§impl Clone for SupervisorHandle
impl Clone for SupervisorHandle
Source§fn clone(&self) -> SupervisorHandle
fn clone(&self) -> SupervisorHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SupervisorHandle
impl !RefUnwindSafe for SupervisorHandle
impl Send for SupervisorHandle
impl Sync for SupervisorHandle
impl Unpin for SupervisorHandle
impl UnsafeUnpin for SupervisorHandle
impl !UnwindSafe for SupervisorHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);