Skip to content

Commit

Permalink
pubsys: only create tokio runtime when needed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tjkirch committed Aug 12, 2020
1 parent fb4e879 commit 0eb5a2d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions tools/pubsys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
Expand Down Expand Up @@ -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<T> = std::result::Result<T, error::Error>;

0 comments on commit 0eb5a2d

Please sign in to comment.