23 lines
767 B
Rust
23 lines
767 B
Rust
//! Durable housekeeping does not depend on device traffic or an in-memory lease.
|
|
use anyhow::Result;
|
|
use sqlx::{Postgres, Transaction};
|
|
use uuid::Uuid;
|
|
pub async fn maintain(tx: &mut Transaction<'_, Postgres>, agent: Option<Uuid>) -> Result<()> {
|
|
sqlx::query("SELECT maintain_current_customer($1)")
|
|
.bind(agent)
|
|
.execute(&mut **tx)
|
|
.await?;
|
|
Ok(())
|
|
}
|
|
pub fn start(state: crate::State) {
|
|
tokio::spawn(async move {
|
|
let mut timer = tokio::time::interval(std::time::Duration::from_secs(1));
|
|
loop {
|
|
timer.tick().await;
|
|
if sqlx::query("SELECT maintain_customers()").execute(&state.pool).await.is_err() {
|
|
eprintln!("customer housekeeping failed");
|
|
}
|
|
}
|
|
});
|
|
}
|