aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2025-06-27 17:46:13 +0100
committerTomasz Kramkowski <tomasz@kramkow.ski>2025-06-27 17:46:13 +0100
commit214bf200d55575acacf03a83495ea65a0eda6e0d (patch)
tree8b785263e461fe81311115da27ac229bff251cfe /src
parent1fde6642082ece4b6c64e29f2983e0f988ce2b59 (diff)
downloadmqttr-214bf200d55575acacf03a83495ea65a0eda6e0d.tar.gz
mqttr-214bf200d55575acacf03a83495ea65a0eda6e0d.tar.xz
mqttr-214bf200d55575acacf03a83495ea65a0eda6e0d.zip
Process timeout after 60 seconds
Diffstat (limited to 'src')
-rw-r--r--src/main.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index bc9a7b5..cf451dd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,11 +3,11 @@
// TODO: Log levels
-use std::{path::PathBuf, process::Stdio};
+use std::{path::PathBuf, process::Stdio, time::Duration};
use anyhow::Context;
use rumqttc::{Event::Incoming, Packet, Publish, QoS};
-use tokio::{io::AsyncWriteExt, process::Command};
+use tokio::{io::AsyncWriteExt, process::Command, time::timeout};
mod config;
@@ -87,8 +87,10 @@ async fn main() -> anyhow::Result<()> {
let program = program.clone();
let p = p.clone();
tokio::spawn(async move {
- if let Err(e) = run(&program, &p).await {
- eprintln!("error: Failed to run {program:?}: {e:?}");
+ match timeout(Duration::from_secs(60), run(&program, &p)).await {
+ Err(_) => eprintln!("error: Execution of {program:?} for message {p:?} timed out"),
+ Ok(Err(e)) => eprintln!("error: Failed to run {program:?}: {e:?}"),
+ _ => (),
}
});
}