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>) -> Self
pub fn new(idle_window: Option<Duration>) -> Self
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) -> Self
Sourcepub fn while_busy(self, while_busy: bool) -> Self
pub fn while_busy(self, while_busy: bool) -> Self
End once the daemon reports no running exec.
Sourcepub fn max_duration(self, max_duration: Option<Duration>) -> Self
pub fn max_duration(self, max_duration: Option<Duration>) -> Self
End after this long even if still busy.
pub fn tolerated_errors(self, tolerated_errors: u32) -> Self
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<RunningGate>,
) -> Result<KeepAwakeTask, Error>
pub fn spawn( self, session: Session, running: Option<RunningGate>, ) -> 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.