use std::{sync::Arc, time::Duration};
use crate::{
ProcFuture, ProcessControlHandler, ProcessOperation, Runnable, RuntimeControlMessage,
RuntimeGuard,
};
#[derive(Debug, Default)]
pub struct IdleProcess {
runtime_guard: RuntimeGuard,
}
impl IdleProcess {
pub fn new() -> Self {
Self {
runtime_guard: RuntimeGuard::default(),
}
}
}
impl Runnable for IdleProcess {
fn process_start(&self) -> ProcFuture<'_> {
Box::pin(async {
let ticker = self.runtime_guard.runtime_ticker().await;
loop {
let sleep = tokio::time::sleep(Duration::from_secs(3600));
match ticker.tick(sleep).await {
ProcessOperation::Next(_) => continue,
ProcessOperation::Control(RuntimeControlMessage::Shutdown) => break,
ProcessOperation::Control(_) => continue,
}
}
Ok(())
})
}
fn process_handle(&self) -> Arc<dyn ProcessControlHandler> {
self.runtime_guard.handle()
}
fn process_name(&self) -> std::borrow::Cow<'static, str> {
std::borrow::Cow::Borrowed("IdleProcess")
}
}