pub struct KeepAwake { /* private fields */ }Expand description
A keepalive’s policy. Build with KeepAwake::new, check with KeepAwake::validate.
Implementations§
Source§impl KeepAwake
impl KeepAwake
Sourcepub fn new(idle_window: Option<Duration>) -> KeepAwake
pub fn new(idle_window: Option<Duration>) -> KeepAwake
A keepalive for a VM whose maxIdleDurationSeconds is idle_window, or the
platform minimum when unknown. The interval defaults to a third of the window,
at most DEFAULT_KEEP_AWAKE_INTERVAL.
pub fn interval(self, interval: Duration) -> KeepAwake
Sourcepub fn while_busy(self, while_busy: bool) -> KeepAwake
pub fn while_busy(self, while_busy: bool) -> KeepAwake
End once the daemon reports no running exec.
Sourcepub fn max_duration(self, max_duration: Option<Duration>) -> KeepAwake
pub fn max_duration(self, max_duration: Option<Duration>) -> KeepAwake
End after this long even if still busy.
pub fn tolerated_errors(self, tolerated_errors: u32) -> KeepAwake
pub fn interval_value(&self) -> Duration
pub fn idle_window_value(&self) -> Duration
Sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Refuses a policy that could let the VM suspend. See the module docs for the cap.
Sourcepub async fn run<P, F, S>(
&self,
probe: P,
stop: S,
) -> Result<KeepAwakeReport, Error>
pub async fn run<P, F, S>( &self, probe: P, stop: S, ) -> Result<KeepAwakeReport, Error>
Polls probe until stop resolves, the policy ends it, or a poll fails for good.
The first poll is immediate. probe answers Ok(None) when the VM is no longer
running. A retryable failure is retried after one second, up to tolerated_errors
in a row; any other failure ends the keepalive with that error.
Source§impl KeepAwake
impl KeepAwake
Sourcepub fn spawn(
self,
session: Session,
running: Option<Box<dyn Fn() -> bool + Send + Sync>>,
) -> Result<KeepAwakeTask, Error>
pub fn spawn( self, session: Session, running: Option<Box<dyn Fn() -> bool + Send + Sync>>, ) -> Result<KeepAwakeTask, Error>
Validates the policy and starts polling session on the current tokio runtime.
running, when given, is checked before every poll; once it answers false the
task ends with KeepAwakeEnd::NotRunning without polling again. Panics outside a
tokio runtime, like tokio::spawn.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KeepAwake
impl RefUnwindSafe for KeepAwake
impl Send for KeepAwake
impl Sync for KeepAwake
impl Unpin for KeepAwake
impl UnsafeUnpin for KeepAwake
impl UnwindSafe for KeepAwake
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,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§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