Add global cleanup.
parent
613065de85
commit
e15b0fd95e
@ -0,0 +1,38 @@
|
||||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
use std::time::SystemTime;
|
||||
|
||||
use crate::db::DbHandle;
|
||||
|
||||
pub(crate) const ACTION_CLEANUP: &str = "cleanup";
|
||||
const ACTION_CLEANUP_INTERVAL: u64 = 1209600;
|
||||
const ACTION_CLEANUP_LOG_RETENTION_DAYS: u64 = 30;
|
||||
|
||||
pub(crate) fn cleanup(db_conn: &mut DbHandle) -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Performing global cleanup.");
|
||||
Command::new("poudriere")
|
||||
.arg("distclean")
|
||||
.arg("-v")
|
||||
.arg("-y")
|
||||
.arg("-a")
|
||||
.status()?
|
||||
.exit_ok()?;
|
||||
Command::new("poudriere")
|
||||
.arg("logclean")
|
||||
.arg("-v")
|
||||
.arg("-y")
|
||||
.arg(ACTION_CLEANUP_LOG_RETENTION_DAYS.to_string())
|
||||
.status()?
|
||||
.exit_ok()?;
|
||||
let next_run = (SystemTime::now() + Duration::from_secs(ACTION_CLEANUP_INTERVAL))
|
||||
.duration_since(SystemTime::UNIX_EPOCH)?
|
||||
.as_secs();
|
||||
|
||||
let tx = db_conn.conn.transaction()?;
|
||||
tx.execute(
|
||||
"UPDATE global_action SET next_run=$1 WHERE name=$2",
|
||||
(next_run, ACTION_CLEANUP),
|
||||
)?;
|
||||
tx.commit()?;
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue