Skip to main content

Wora

Struct Wora 

Source
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: String

application name

§dirs: Dirs

common directories for all executors

§initial_working_dir: PathBuf

current directory where the process was invoked (an executor will likely override this)

§host: Host

host info/stats

§sender: Sender<Event<AppEv>>

Event producer

§receiver: Receiver<Event<AppEv>>

Event receiver

§leadership: Leadership

leadership state

Implementations§

Source§

impl<AppEv: Send + Sync + 'static, AppMetric: Send + Sync + 'static> Wora<AppEv, AppMetric>

WORA API

Source

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.

Source

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.

Source

pub fn stats_from_start(&self) -> &HostStats

Return the host statistics captured when the runtime started.

Source

pub fn resources(&self) -> Option<&RuntimeResources>

Inspect shared runner admission state, if explicitly configured.

Source

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.

Source

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.

Source

pub fn dirs(&self) -> &Dirs

Return the executor directory layout.

Source

pub async fn emit_event(&self, ev: Event<AppEv>)

Emit an event onto the application event channel.

Source

pub fn host_os_name(&self) -> &str

Return the host operating system identifier.

Source

pub fn host_os_version(&self) -> Option<String>

Return the host operating system version, when available.

Source

pub fn host_architecture(&self) -> Option<String>

Return the host architecture, when available.

Source

pub fn host_hostname(&self) -> Option<String>

Return the host name, when available.

Source

pub fn host_cpu_count(&self) -> usize

Return the number of physical CPU cores detected at startup.

Source

pub fn host_cpu_max(&self) -> usize

Return the number of logical CPUs detected at startup.

Source

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.

Source

pub fn report_health(&self, state: HealthState)

Report application health to the runtime supervisor.

Source

pub fn report_readiness(&self, state: ReadinessState)

Report application readiness to the runtime supervisor.

Source

pub fn begin_draining(&self)

Mark the runtime as draining and no longer willing to accept new work.

Source

pub fn begin_stopping(&self)

Mark the runtime as stopping.

Source

pub fn health_state(&self) -> HealthState

Return the latest application health state known to the runtime.

Source

pub fn readiness_state(&self) -> ReadinessState

Return the latest application readiness state known to the runtime.

Source

pub async fn apply_reload_event<A>( &self, app: &mut A, fs: impl WFS + 'static, event: &Event<AppEv>, ) -> Result<ReloadHandling, ReloadError>
where A: App<AppEv, AppMetric> + Send,

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.

Source

pub async fn run_event_loop<A, F>( &mut self, app: &mut A, fs: impl WFS + 'static, handler: F, ) -> Result<MainRetryAction, ReloadError>
where A: App<AppEv, AppMetric> + Send, F: FnMut(&mut A, &mut Wora<AppEv, AppMetric>, Event<AppEv>) -> EventLoopAction + Send,

Run a reload-aware event loop for event-driven applications.

Typed config and secret reloads are applied before handler receives the event.

Source

pub async fn schedule_event(&self, duration: Duration, ev: Event<AppEv>)

Sleep for duration, then emit ev.

Source

pub async fn schedule_task<F, Fut>( &self, duration: Duration, future: F, ) -> JoinHandle<TaskOp> ⓘ
where F: Fn(Sender<O11yEvent<AppMetric>>) -> Fut + Send + 'static, Fut: Future<Output = TaskOp> + Send,

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.

Source

pub fn try_schedule_task<F, Fut>( &self, duration: Duration, future: F, ) -> Result<JoinHandle<TaskOp>, ResourceError>
where F: Fn(Sender<O11yEvent<AppMetric>>) -> Fut + Send + 'static, Fut: Future<Output = TaskOp> + Send,

Spawn a scheduled loop only if a task slot is immediately available. Refusal happens before spawning; admitted work holds its lease until drop.

Auto Trait Implementations§

§

impl<AppEv, AppMetric> !RefUnwindSafe for Wora<AppEv, AppMetric>

§

impl<AppEv, AppMetric> !UnwindSafe for Wora<AppEv, AppMetric>

§

impl<AppEv, AppMetric> Freeze for Wora<AppEv, AppMetric>
where Sender<Event<AppEv>>: Freeze, Receiver<Event<AppEv>>: Freeze, O11yProcessorOptions<AppMetric>: Freeze,

§

impl<AppEv, AppMetric> Send for Wora<AppEv, AppMetric>
where Sender<Event<AppEv>>: Send, Receiver<Event<AppEv>>: Send, O11yProcessorOptions<AppMetric>: Send,

§

impl<AppEv, AppMetric> Sync for Wora<AppEv, AppMetric>
where Sender<Event<AppEv>>: Sync, Receiver<Event<AppEv>>: Sync, O11yProcessorOptions<AppMetric>: Sync,

§

impl<AppEv, AppMetric> Unpin for Wora<AppEv, AppMetric>
where Sender<Event<AppEv>>: Unpin, Receiver<Event<AppEv>>: Unpin, O11yProcessorOptions<AppMetric>: Unpin,

§

impl<AppEv, AppMetric> UnsafeUnpin for Wora<AppEv, AppMetric>
where Sender<Event<AppEv>>: UnsafeUnpin, Receiver<Event<AppEv>>: UnsafeUnpin, O11yProcessorOptions<AppMetric>: UnsafeUnpin,

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<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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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