Skip to content

Commit

Permalink
feat(alerts): add --timeout for alerts to avoid blocking indefinitely
Browse files Browse the repository at this point in the history
  • Loading branch information
passcod committed Jan 28, 2025
1 parent 210ec12 commit 4935514
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/bestool/src/actions/tamanu/alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use reqwest::Url;
use serde_json::json;
use sysinfo::System;
use tera::{Context as TeraCtx, Tera};
use tokio::{io::AsyncReadExt as _, task::JoinSet};
use tokio::{io::AsyncReadExt as _, task::JoinSet, time::timeout};
use tokio_postgres::types::{IsNull, ToSql, Type};
use tracing::{debug, error, info, instrument, warn};
use walkdir::WalkDir;
Expand Down Expand Up @@ -711,15 +711,16 @@ pub async fn run(ctx: Context<TamanuArgs, AlertsArgs>) -> Result<()> {
let internal_ctx = internal_ctx.clone();
let dry_run = ctx.args_sub.dry_run;
let mailgun = mailgun.clone();
set.spawn(async move {
let timeout_d: Duration = ctx.args_sub.timeout.into();
set.spawn(timeout(timeout_d, async move {
let error = format!("while executing alert: {}", alert.file.display());
if let Err(err) = execute_alert(internal_ctx, mailgun, alert, dry_run)
.await
.wrap_err(error)
{
eprintln!("{err:?}");
}
});
}));
}

while let Some(res) = set.join_next().await {
Expand Down

0 comments on commit 4935514

Please sign in to comment.