AT-based link agregator. Mirror of https://github.com/likeandscribe/frontpage
at main 66 lines 2.1 kB view raw
1use std::path::PathBuf; 2 3use chrono::TimeZone; 4use structopt::StructOpt; 5 6#[derive(StructOpt, Debug)] 7#[structopt(name = "drainpipe")] 8enum Opt { 9 SetCursor { 10 #[structopt(long, env = "STORE_LOCATION", parse(from_os_str))] 11 db: PathBuf, 12 13 #[structopt(name = "TIME_US")] 14 value: u64, 15 }, 16 17 GetCursor { 18 #[structopt(long, env = "STORE_LOCATION", parse(from_os_str))] 19 db: PathBuf, 20 }, 21 22 GetDeadLetterMessages { 23 #[structopt(long, env = "STORE_LOCATION", parse(from_os_str))] 24 db: PathBuf, 25 }, 26} 27 28fn main() { 29 let cwd = std::env::current_dir().expect("Could not get current directory"); 30 31 dotenv_flow::from_filename(cwd.join(".env.local")).ok(); 32 dotenv_flow::from_filename(cwd.join(".env")).ok(); 33 34 match Opt::from_args() { 35 Opt::SetCursor { db, value } => { 36 let store = drainpipe_store::Store::open(&db).expect("Could not open store"); 37 store.set_cursor(value).expect("Could not set cursor"); 38 store.flush().expect("Could not flush store"); 39 println!("Cursor set to: {}", value); 40 } 41 42 Opt::GetCursor { db } => { 43 let store = drainpipe_store::Store::open(&db).expect("Could not open store"); 44 if let Some(cursor) = store.get_cursor().expect("Could not get cursor") { 45 println!( 46 "Cursor: {} ({:?})", 47 cursor, 48 chrono::Utc.timestamp_micros(cursor as i64).unwrap() 49 ); 50 } else { 51 println!("Cursor not set"); 52 std::process::exit(1); 53 } 54 } 55 56 Opt::GetDeadLetterMessages { db } => { 57 let store = drainpipe_store::Store::open(&db).expect("Could not open store"); 58 let messages = store 59 .get_dead_letter_messages() 60 .expect("Could not get dead letter messages"); 61 for message in messages { 62 println!("{}", serde_json::to_string_pretty(&message).unwrap()); 63 } 64 } 65 } 66}