Skip to content

Commit e29bd12

Browse files
authored
fix(cli): introduce timeout flag for the bundle command (#603)
1 parent 917a3b8 commit e29bd12

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

cli/src/flags.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ fn get_bundle_command() -> Command {
364364
.default_value("false")
365365
.value_parser(FalseyValueParser::new()),
366366
)
367+
.arg(
368+
arg!(--"timeout" <SECONDS>)
369+
.help("Maximum time in seconds that can be waited for the bundle to complete.")
370+
.value_parser(value_parser!(u64).range(..u64::MAX))
371+
)
367372
}
368373

369374
fn get_unbundle_command() -> Command {

cli/src/main.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::path::PathBuf;
66
use std::process::ExitCode;
77
use std::str::FromStr;
88
use std::sync::Arc;
9+
use std::time::Duration;
910

1011
use anyhow::bail;
1112
use anyhow::Context;
@@ -34,6 +35,7 @@ use flags::EszipV2ChecksumKind;
3435
use flags::OtelConsoleConfig;
3536
use flags::OtelKind;
3637
use log::warn;
38+
use tokio::time::timeout;
3739

3840
mod env;
3941
mod flags;
@@ -319,6 +321,10 @@ fn main() -> Result<ExitCode, anyhow::Error> {
319321
} else {
320322
vec![]
321323
};
324+
let timeout_dur = sub_matches
325+
.get_one::<u64>("timeout")
326+
.cloned()
327+
.map(Duration::from_secs);
322328

323329
if import_map_path.is_some() {
324330
warn!(concat!(
@@ -382,14 +388,24 @@ fn main() -> Result<ExitCode, anyhow::Error> {
382388
emitter_factory.set_deno_options(builder.build()?);
383389

384390
let mut metadata = Metadata::default();
385-
let eszip = generate_binary_eszip(
391+
let eszip_fut = generate_binary_eszip(
386392
&mut metadata,
387393
Arc::new(emitter_factory),
388394
None,
389395
maybe_checksum_kind,
390396
Some(static_patterns),
391-
)
392-
.await?;
397+
);
398+
399+
let eszip = if let Some(dur) = timeout_dur {
400+
match timeout(dur, eszip_fut).await {
401+
Ok(eszip) => eszip,
402+
Err(_) => {
403+
bail!("Failed to complete the bundle within the given time.")
404+
}
405+
}
406+
} else {
407+
eszip_fut.await
408+
}?;
393409

394410
let bin = eszip.into_bytes();
395411

0 commit comments

Comments
 (0)