Skip to main content

ActiveRun

Struct ActiveRun 

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

Cheap to clone (an Arc<Mutex<..>> underneath), matching crate::state::AppState’s own Clone requirement for axum’s State extractor.

Implementations§

Source§

impl ActiveRun

Source

pub async fn start( &self, run_id: i64, cancel: CtrlCHandle, task: impl Future<Output = ()> + Send + 'static, ) -> Result<(), RunAlreadyActive>

Registers task as a background tune, recording cancel so a later ActiveRun::cancel or ActiveRun::cancel_and_wait call can trigger it. The registration is released automatically after the task returns or panics. If registration is rejected, task is dropped without being spawned, releasing anything it captured (such as Demo concurrency permits).

Multiple tune tasks may be registered at the same time. The only conflict is with an exclusive post-hoc write/revert reservation, which protects direct live-loop mutation.

Source

pub async fn reserve(&self, run_id: i64) -> Result<(), RunAlreadyActive>

Reserves the registry for a short operation the caller awaits directly – currently only a post-hoc PID write or revert (api-post-run-write). Unlike ActiveRun::start, nothing is spawned here: the caller must still call ActiveRun::release itself once its own operation finishes, on every exit path including an error return.

The reservation is accepted only when all tune tasks and any other reservation have finished. This keeps direct live-loop mutation serialized without preventing independent tune tasks from running concurrently.

Source

pub async fn exclusive_id(&self) -> Option<i64>

Returns the run id associated with the current exclusive write/revert reservation, if any. This is a cheap, non-authoritative pre-check; ActiveRun::start still re-checks under the same mutex to close the race with a reservation beginning between this call and the actual task registration.

Source

pub async fn active_run_ids(&self) -> Vec<i64>

Returns the ids of all registered background tune tasks. Cancellation always targets one id at a time.

Source

pub async fn cancel(&self, run_id: i64) -> bool

Triggers cancellation for run_id if that tune is registered, exactly as if Ctrl+C had been pressed against an equivalent CLI-driven run. Returns whether a matching tune or exclusive reservation was found.

Source

pub async fn release(&self, run_id: i64)

Releases the tune registration or exclusive reservation for run_id. Spawned tune registrations release themselves; direct callers use this for exclusive reservations. A no-op if the id is not registered, which is expected when graceful shutdown has already taken the registry’s entries for cancellation and waiting.

Source

pub async fn cancel_and_wait(&self, wait_timeout: Duration)

Triggers cancellation for every registered tune and waits up to wait_timeout for their background tasks to actually finish, including restore attempts. If the timeout elapses, the remaining tasks are abandoned and a loud error names all affected runs.

Trait Implementations§

Source§

impl Clone for ActiveRun

Source§

fn clone(&self) -> ActiveRun

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Default for ActiveRun

Source§

fn default() -> ActiveRun

Returns the “default value” for a type. 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

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

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

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
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

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

impl<L> LayerExt<L> for L

§

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

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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