From 0eb5a2dc29592343a1d3055683a977d32ac6a3e7 Mon Sep 17 00:00:00 2001 From: Tom Kirchner Date: Wed, 12 Aug 2020 16:49:42 -0700 Subject: [PATCH] pubsys: only create tokio runtime when needed tough-ssm creates its own tokio runtime for making SSM calls, so we can't use it inside our own tokio runtime. This change removes the general `[tokio::main]` annotation that creates a runtime for the entire app, and instead only creates a runtime inside the `ami` subcommand that needs one. We can switch back to the annotation when tough-ssm moves to an async interface. --- tools/pubsys/src/main.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tools/pubsys/src/main.rs b/tools/pubsys/src/main.rs index 7711fe2ffd3..1f42b69eb27 100644 --- a/tools/pubsys/src/main.rs +++ b/tools/pubsys/src/main.rs @@ -32,8 +32,9 @@ use snafu::ResultExt; use std::path::PathBuf; use std::process; use structopt::StructOpt; +use tokio::runtime::Runtime; -async fn run() -> Result<()> { +fn run() -> Result<()> { // Parse and store the args passed to the program let args = Args::from_args(); @@ -43,13 +44,17 @@ async fn run() -> Result<()> { match args.subcommand { SubCommand::Repo(ref repo_args) => repo::run(&args, &repo_args).context(error::Repo), - SubCommand::Ami(ref ami_args) => aws::ami::run(&args, &ami_args).await.context(error::Ami), + SubCommand::Ami(ref ami_args) => { + let mut rt = Runtime::new().context(error::Runtime)?; + rt.block_on(async { + aws::ami::run(&args, &ami_args).await.context(error::Ami) + }) + }, } } -#[tokio::main] -async fn main() { - if let Err(e) = run().await { +fn main() { + if let Err(e) = run() { eprintln!("{}", e); process::exit(1); } @@ -103,14 +108,17 @@ mod error { #[derive(Debug, Snafu)] #[snafu(visibility = "pub(super)")] pub(super) enum Error { + #[snafu(display("Failed to build AMI: {}", source))] + Ami { source: crate::aws::ami::Error }, + #[snafu(display("Logger setup error: {}", source))] Logger { source: simplelog::TermLogError }, #[snafu(display("Failed to build repo: {}", source))] Repo { source: crate::repo::Error }, - #[snafu(display("Failed to build AMI: {}", source))] - Ami { source: crate::aws::ami::Error }, + #[snafu(display("Failed to create async runtime: {}", source))] + Runtime { source: std::io::Error }, } } type Result = std::result::Result;