From 214bf200d55575acacf03a83495ea65a0eda6e0d Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 27 Jun 2025 17:46:13 +0100 Subject: Process timeout after 60 seconds --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main.rs') 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:?}"), + _ => (), } }); } -- cgit v1.2.3-70-g09d2