Skip to main content

Lifecycle

Struct Lifecycle 

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

The shared, cloneable lifecycle handle. One is created per server; the accept loop consults it per connection/request and an orchestrator flips readiness / requests drain through it.

Implementations§

Source§

impl Lifecycle

Source

pub fn new(config: LifecycleConfig) -> Lifecycle

Create a lifecycle from config. The server starts NOT ready by default — an orchestrator calls Lifecycle::set_ready once dependencies are wired — EXCEPT the plain-serve config, whose readiness the entry sets to true up front (there is no orchestrator on that path).

Source

pub fn config(&self) -> &LifecycleConfig

The config this lifecycle runs under (for the accept loop’s timeout / body cap / correlation-id policy).

Source

pub fn set_ready(&self, ready: bool)

Flip the readiness gate. false → new requests are shed with 503 (load balancers stop routing); true → traffic is served. Independent of liveness (the loop stays up either way).

Source

pub fn is_ready(&self) -> bool

Whether the server is currently serving traffic (ready and not draining).

Source

pub fn is_draining(&self) -> bool

Whether a graceful drain is in progress.

Source

pub fn admit(&self) -> Admission

THE admission decision — the one law both tiers apply per request:

try_acquire (never .await) is the backpressure keystone: admission never blocks the accept loop, so an over-capacity flood is shed, not buffered into a hang.

Source

pub fn inflight(&self) -> usize

How many in-flight slots are currently occupied (a handler is running).

Source

pub fn correlation_id(&self, client_supplied: Option<&str>) -> String

The correlation id for a response: the client’s X-Correlation-Id (verbatim, when present and non-empty) else a freshly assigned one. Two concurrent no-id requests get DISTINCT ids (the counter is atomic).

Source

pub fn assign_correlation_id(&self) -> String

Assign a fresh, unique correlation id (monotonic counter + per-process nonce) — cheap and non-blocking, no RNG on the hot path.

Source

pub fn drain_signal(&self) -> Arc<Notify>

The signal the accept loop select!s on so drain can stop it. Pinged exactly once by Lifecycle::drain; combined with the is_draining flag check in the loop, a stop can never be missed.

Source

pub fn notify_slot_freed(&self)

Call when a slot frees (a SlotGuard dropped) so a pending drain waiter re-checks the in-flight count promptly rather than polling.

Source

pub async fn drain(&self, deadline: Duration) -> DrainOutcome

Begin a GRACEFUL drain and wait up to deadline for in-flight requests to finish. Flips the draining flag (the accept loop stops taking new connections; new requests are shed with 503), then awaits in-flight → zero OR the deadline, returning the still-running count at the deadline as DrainOutcome::dropped. Never hangs past deadline.

Source§

impl Lifecycle

Source

pub fn probe_response(&self, path: &str) -> Option<HttpResponse>

The answer a configured probe path owes, or None when the path is the program’s own.

Called BEFORE admission, so a probe is never shed by backpressure and never consumes a slot — a monitor asking “are you alive” during an overload must get an answer, not the overload. Readiness reports whether this server wants traffic right now (503 once draining, so a load balancer stops sending while in-flight work finishes); liveness reports only that the process is answering, and deliberately stays 200 through a drain, because a draining server is healthy and killing it would abandon the requests it is finishing.

Both paths are opt-in. With neither configured this returns None for every path, so no route is taken away from the program and the byte-for-byte cross-tier differential is unperturbed.

Trait Implementations§

Source§

impl Clone for Lifecycle

Source§

fn clone(&self) -> Lifecycle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

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

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,