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
impl ActiveRun
Sourcepub async fn start(
&self,
run_id: i64,
cancel: CtrlCHandle,
task: impl Future<Output = ()> + Send + 'static,
) -> Result<(), RunAlreadyActive>
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.
Sourcepub async fn reserve(&self, run_id: i64) -> Result<(), RunAlreadyActive>
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.
Sourcepub async fn exclusive_id(&self) -> Option<i64>
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.
Sourcepub async fn active_run_ids(&self) -> Vec<i64>
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.
Sourcepub async fn cancel(&self, run_id: i64) -> bool
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.
Sourcepub async fn release(&self, run_id: i64)
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.
Sourcepub async fn cancel_and_wait(&self, wait_timeout: Duration)
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§
Auto Trait Implementations§
impl !RefUnwindSafe for ActiveRun
impl !UnwindSafe for ActiveRun
impl Freeze for ActiveRun
impl Send for ActiveRun
impl Sync for ActiveRun
impl Unpin for ActiveRun
impl UnsafeUnpin for ActiveRun
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].