Add ports tree updating.
parent
f1db62190a
commit
613065de85
@ -0,0 +1,4 @@
|
||||
mod ports_tree;
|
||||
|
||||
pub(crate) use ports_tree::update_ports_tree;
|
||||
pub(crate) use ports_tree::ACTION_UPDATE_PORTS_TREE;
|
@ -0,0 +1,25 @@
|
||||
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<dyn std::error::Error>> {
|
||||
println!("Updating ports tree.");
|
||||
Command::new("portshaker").arg("-U").status()?;
|
||||
Command::new("portshaker").arg("-M").status()?;
|
||||
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(())
|
||||
}
|
Loading…
Reference in New Issue