Grayson Hay
Posted on May 30, 2024
Recently, I needed to kick off a long running process for encoding videos using ffmpeg in the middle of handling an SQS message. In order to keep the message from showing back up in the queue before the video processing is finished.
So that means, I need to be able to send the change message visibility timeout periodically during the process. so, I came up with this little function to help. It calls a โprogressโ function every 10 seconds while the command is executing, and then ends once itโs done.
Using tokio as the Async Runtime
pub async fn exec<F, Fut>(mut cmd: Command, progress: F) -> Result<Output, ProgressingExecError>
where
F: Fn() -> Fut,
Fut: Future<Output = ()>,
{
let (tx, mut rx) = oneshot::channel();
let mut interval = interval(Duration::from_millis(10000));
tokio::spawn(async move {
let output = cmd.output().await;
let _ = tx.send(output);
});
loop {
tokio::select! {
_ = interval.tick() => progress().await,
msg = &mut rx => return Ok(msg??)
}
}
}
๐ ๐ช ๐
๐ฉ
Grayson Hay
Posted on May 30, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
rust โ๏ธ Rust vs Go vs Bun vs Node.js: The Ultimate 2024 Performance Showdown ๐
October 5, 2024