Skip to content

Commit

Permalink
feat: add retry flag
Browse files Browse the repository at this point in the history
  • Loading branch information
wvffle committed Nov 4, 2024
1 parent 9608806 commit e09e000
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub struct Config {
/// If set, the bridge will check for new Factorio Friday Facts and send them to the chat.
#[arg(long, env = "FACTORIO_FRIDAY_FACTS")]
pub fff: bool,

/// Retry connection if app crashed or server is down
#[arg(short = 'r', long, env)]
pub retry: bool,
}

impl Config {
Expand Down
18 changes: 15 additions & 3 deletions src/tasks/factorio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ use tokio::sync::mpsc;
use tracing::{error, info};

pub async fn run(tx: mpsc::Sender<Signal>) -> Result<()> {
if CONFIG.retry {
loop {
if let Err(e) = create_reader(&tx).await {
error!("Error reading log file: {}", e);
}
}
}

create_reader(&tx).await?;

Ok(())
}

async fn create_reader(tx: &mpsc::Sender<Signal>) -> Result<()> {
crate::log_reader::read_log(|line| async {
if let Some((username, message)) = parse_log_line(line) {
tx.send(Signal::MessageFromFactorio { username, message })
.await
.unwrap();
}
})
.await?;

Ok(())
.await
}

pub async fn send(message: &str) {
Expand Down

0 comments on commit e09e000

Please sign in to comment.