Skip to content

Commit e09e000

Browse files
committed
feat: add retry flag
1 parent 9608806 commit e09e000

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ pub struct Config {
4646
/// If set, the bridge will check for new Factorio Friday Facts and send them to the chat.
4747
#[arg(long, env = "FACTORIO_FRIDAY_FACTS")]
4848
pub fff: bool,
49+
50+
/// Retry connection if app crashed or server is down
51+
#[arg(short = 'r', long, env)]
52+
pub retry: bool,
4953
}
5054

5155
impl Config {

src/tasks/factorio.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@ use tokio::sync::mpsc;
88
use tracing::{error, info};
99

1010
pub async fn run(tx: mpsc::Sender<Signal>) -> Result<()> {
11+
if CONFIG.retry {
12+
loop {
13+
if let Err(e) = create_reader(&tx).await {
14+
error!("Error reading log file: {}", e);
15+
}
16+
}
17+
}
18+
19+
create_reader(&tx).await?;
20+
21+
Ok(())
22+
}
23+
24+
async fn create_reader(tx: &mpsc::Sender<Signal>) -> Result<()> {
1125
crate::log_reader::read_log(|line| async {
1226
if let Some((username, message)) = parse_log_line(line) {
1327
tx.send(Signal::MessageFromFactorio { username, message })
1428
.await
1529
.unwrap();
1630
}
1731
})
18-
.await?;
19-
20-
Ok(())
32+
.await
2133
}
2234

2335
pub async fn send(message: &str) {

0 commit comments

Comments
 (0)