use std::process::Command; use std::time::Duration; use std::time::SystemTime; use crate::db::DbHandle; pub(crate) const ACTION_UPDATE_PORTS_TREE: &str = "update_ports_tree"; const ACTION_UPDATE_PORTS_TREE_INTERVAL: u64 = 86400; pub(crate) fn update_ports_tree(db_conn: &mut DbHandle) -> Result<(), Box> { println!("Updating ports tree."); Command::new("portshaker").arg("-U").status()?.exit_ok()?; Command::new("portshaker").arg("-M").status()?.exit_ok()?; let next_run = (SystemTime::now() + Duration::from_secs(ACTION_UPDATE_PORTS_TREE_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_UPDATE_PORTS_TREE), )?; tx.commit()?; Ok(()) }