diff options
| author | Nathan Perry <np@nathanperry.dev> | 2024-08-06 10:50:19 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2024-08-06 10:50:19 -0400 |
| commit | 4ae023ba5bca6de61eaa123002e228d6cbb60753 (patch) | |
| tree | 924ff1bd79424ec149c34f32eac6448a9248a243 /src | |
| parent | 72d9bbe15220c21909dec8e30fb80729a24cec72 (diff) | |
remove restart loop
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 51 |
1 files changed, 2 insertions, 49 deletions
diff --git a/src/main.rs b/src/main.rs index 93d4d2b..e4f2014 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,55 +5,8 @@ #![feature(box_patterns)] #![allow(deprecated)] -use std::time::{ - Duration, - Instant, -}; - -use log::{ - error, - info, -}; - -const BACKOFF_FACTOR: f64 = 2.0; -const MAX_BACKOFFS: usize = 3; -const BACKOFF_INIT: f64 = 100.0; - -const MIN_RUN_DURATION: Duration = Duration::from_secs(120); - #[tokio::main] -async fn main() { +async fn main() -> anyhow::Result<()> { thulani::log_setup::init(false).expect("initializing logging"); - - let mut backoff_count: usize = 0; - - loop { - let start = Instant::now(); - - info!("starting bot"); - match thulani::bot::run().await { - Err(e) => { - error!("error encountered running client: {:?}", e); - }, - _ => { - // NOTE: we MUST have gotten here through SIGINT/SIGTERM handlers - std::process::exit(0); - }, - } - - if Instant::now() - start >= MIN_RUN_DURATION { - backoff_count = 0; - continue; - } - - backoff_count += 1; - if backoff_count >= MAX_BACKOFFS { - panic!("restarted bot too many times"); - } - - let backoff_millis = (BACKOFF_INIT * BACKOFF_FACTOR.powi(backoff_count as i32)) as u64; - info!("bot died too quickly. backing off, retrying in {}ms.", backoff_millis); - - tokio::time::sleep(Duration::from_millis(backoff_millis)).await; - } + thulani::bot::run().await } |
