netsky 0.2.0

netsky CLI: the viable system launcher and subcommand dispatcher
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::env;
use std::fs;
use std::thread;
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let db_path = env::args().nth(1).ok_or("missing db path")?;
    let ready_path = env::args().nth(2).ok_or("missing ready path")?;
    let hold_ms: u64 = env::args().nth(3).ok_or("missing hold_ms")?.parse()?;

    let conn = rusqlite::Connection::open(db_path)?;
    conn.busy_timeout(Duration::from_millis(0))?;
    conn.execute_batch("BEGIN EXCLUSIVE;")?;
    fs::write(ready_path, b"ready")?;
    thread::sleep(Duration::from_millis(hold_ms));
    conn.execute_batch("ROLLBACK;")?;
    Ok(())
}