pub struct Wora<AppEv, AppMetric> {
pub app_name: String,
pub dirs: Dirs,
pub initial_working_dir: PathBuf,
pub host: Host,
pub sender: Sender<Event<AppEv>>,
pub receiver: Receiver<Event<AppEv>>,
pub leadership: Leadership,
/* private fields */
}Expand description
Runtime context passed to applications.
Wora gives app lifecycle hooks access to executor directories, host
information, event channels, leadership state, and observability settings.
Fields§
§app_name: Stringapplication name
dirs: Dirscommon directories for all executors
initial_working_dir: PathBufcurrent directory where the process was invoked (an executor will likely override this)
host: Hosthost info/stats
sender: Sender<Event<AppEv>>Event producer
receiver: Receiver<Event<AppEv>>Event receiver
leadership: Leadershipleadership state
Implementations§
Source§impl<AppEv: Send + Sync + 'static, AppMetric: Send + Sync + 'static> Wora<AppEv, AppMetric>
WORA API
impl<AppEv: Send + Sync + 'static, AppMetric: Send + Sync + 'static> Wora<AppEv, AppMetric>
WORA API
Sourcepub fn new(
dirs: &Dirs,
app_name: String,
ev_buf_size: usize,
o11y: O11yProcessorOptions<AppMetric>,
) -> Result<Wora<AppEv, AppMetric>, WoraSetupError>
pub fn new( dirs: &Dirs, app_name: String, ev_buf_size: usize, o11y: O11yProcessorOptions<AppMetric>, ) -> Result<Wora<AppEv, AppMetric>, WoraSetupError>
Create a new runtime context.
Sourcepub fn new_with_runtime_environment<R: RuntimeEnvironment>(
dirs: &Dirs,
app_name: String,
ev_buf_size: usize,
o11y: O11yProcessorOptions<AppMetric>,
runtime_environment: R,
) -> Result<Wora<AppEv, AppMetric>, WoraSetupError>
pub fn new_with_runtime_environment<R: RuntimeEnvironment>( dirs: &Dirs, app_name: String, ev_buf_size: usize, o11y: O11yProcessorOptions<AppMetric>, runtime_environment: R, ) -> Result<Wora<AppEv, AppMetric>, WoraSetupError>
Create a new runtime context with an explicit runtime environment.
Sourcepub fn stats_from_start(&self) -> &HostStats
pub fn stats_from_start(&self) -> &HostStats
Return the host statistics captured when the runtime started.
Sourcepub fn resources(&self) -> Option<&RuntimeResources>
pub fn resources(&self) -> Option<&RuntimeResources>
Inspect shared runner admission state, if explicitly configured.
Sourcepub fn memory_stats(&self) -> Arc<MemorySnapshot> ⓘ
pub fn memory_stats(&self) -> Arc<MemorySnapshot> ⓘ
Return the latest stored host memory sample without performing I/O.
Available before app setup and refreshed at the pipeline’s
O11yPipelineBuilder::host_stats_interval. Reading this value does not
depend on consuming application events. A failed host refresh retains the
previous sample. Each unavailable Linux procfs source is None.
Sourcepub fn subscribe_memory_stats(&self) -> Receiver<Arc<MemorySnapshot>>
pub fn subscribe_memory_stats(&self) -> Receiver<Arc<MemorySnapshot>>
Subscribe to stored memory samples from app or background tasks.
The receiver starts with the current sample. Await changed() for later
samples and use borrow_and_update() to read them. Slow listeners observe
the latest sample without blocking collection. This API also works on
macOS, where snapshots contain portable memory and swap totals.
Sourcepub async fn emit_event(&self, ev: Event<AppEv>)
pub async fn emit_event(&self, ev: Event<AppEv>)
Emit an event onto the application event channel.
Sourcepub fn host_os_name(&self) -> &str
pub fn host_os_name(&self) -> &str
Return the host operating system identifier.
Sourcepub fn host_os_version(&self) -> Option<String>
pub fn host_os_version(&self) -> Option<String>
Return the host operating system version, when available.
Sourcepub fn host_architecture(&self) -> Option<String>
pub fn host_architecture(&self) -> Option<String>
Return the host architecture, when available.
Sourcepub fn host_hostname(&self) -> Option<String>
pub fn host_hostname(&self) -> Option<String>
Return the host name, when available.
Sourcepub fn host_cpu_count(&self) -> usize
pub fn host_cpu_count(&self) -> usize
Return the number of physical CPU cores detected at startup.
Sourcepub fn host_cpu_max(&self) -> usize
pub fn host_cpu_max(&self) -> usize
Return the number of logical CPUs detected at startup.
Sourcepub fn status_handle(&self) -> RuntimeStatusHandle
pub fn status_handle(&self) -> RuntimeStatusHandle
Return the shared runtime status handle.
Applications and background tasks should use this handle, or the
convenience methods on Wora, to report health and readiness changes to
the runtime supervisor.
Sourcepub fn report_health(&self, state: HealthState)
pub fn report_health(&self, state: HealthState)
Report application health to the runtime supervisor.
Sourcepub fn report_readiness(&self, state: ReadinessState)
pub fn report_readiness(&self, state: ReadinessState)
Report application readiness to the runtime supervisor.
Sourcepub fn begin_draining(&self)
pub fn begin_draining(&self)
Mark the runtime as draining and no longer willing to accept new work.
Sourcepub fn begin_stopping(&self)
pub fn begin_stopping(&self)
Mark the runtime as stopping.
Sourcepub fn health_state(&self) -> HealthState
pub fn health_state(&self) -> HealthState
Return the latest application health state known to the runtime.
Sourcepub fn readiness_state(&self) -> ReadinessState
pub fn readiness_state(&self) -> ReadinessState
Return the latest application readiness state known to the runtime.
Sourcepub async fn apply_reload_event<A>(
&self,
app: &mut A,
fs: impl WFS + 'static,
event: &Event<AppEv>,
) -> Result<ReloadHandling, ReloadError>
pub async fn apply_reload_event<A>( &self, app: &mut A, fs: impl WFS + 'static, event: &Event<AppEv>, ) -> Result<ReloadHandling, ReloadError>
Apply a typed config or secret reload event to app.
This helper is intended to be called from App::main when the app
receives Event::ConfigChanged or Event::SecretChanged.
Sourcepub async fn run_event_loop<A, F>(
&mut self,
app: &mut A,
fs: impl WFS + 'static,
handler: F,
) -> Result<MainRetryAction, ReloadError>
pub async fn run_event_loop<A, F>( &mut self, app: &mut A, fs: impl WFS + 'static, handler: F, ) -> Result<MainRetryAction, ReloadError>
Run a reload-aware event loop for event-driven applications.
Typed config and secret reloads are applied before handler receives
the event.
Sourcepub async fn schedule_event(&self, duration: Duration, ev: Event<AppEv>)
pub async fn schedule_event(&self, duration: Duration, ev: Event<AppEv>)
Sleep for duration, then emit ev.
Sourcepub async fn schedule_task<F, Fut>(
&self,
duration: Duration,
future: F,
) -> JoinHandle<TaskOp> ⓘ
pub async fn schedule_task<F, Fut>( &self, duration: Duration, future: F, ) -> JoinHandle<TaskOp> ⓘ
Spawn a periodic background task.
The task receives a clone of the observability sender. Returning
TaskOp::Requeue schedules the next run; returning TaskOp::Abort
stops the loop.
With resource admission configured, waits for a task slot before spawning.
The caller owns this waiting future; use Self::try_schedule_task for
immediate refusal without adding a waiting producer.
Sourcepub fn try_schedule_task<F, Fut>(
&self,
duration: Duration,
future: F,
) -> Result<JoinHandle<TaskOp>, ResourceError>
pub fn try_schedule_task<F, Fut>( &self, duration: Duration, future: F, ) -> Result<JoinHandle<TaskOp>, ResourceError>
Spawn a scheduled loop only if a task slot is immediately available. Refusal happens before spawning; admitted work holds its lease until drop.