Skip to content

Commit

Permalink
Merge pull request #1034 from tjkirch/pubsys-tokio
Browse files Browse the repository at this point in the history
pubsys: only create tokio runtime when needed
  • Loading branch information
tjkirch authored Aug 13, 2020
2 parents fb4e879 + 0eb5a2d commit e3c2495
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 e3c2495

Please sign in to comment.