From e2b1f02953687d0504876d35d0f4b68223e7931e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 17 Aug 2021 12:19:08 +0200 Subject: Revert "Add spinner for establishing database connection" This reverts commit ab04d88ae84c33f3577870c10378f0166adf27bc. Having a progress bar for establishing the database connection was just too much noise visually. Signed-off-by: Matthias Beyer --- src/commands/db.rs | 64 ++++++++++++++++++++++++------------------------- src/commands/release.rs | 14 ++++------- src/db/connection.rs | 15 ++---------- src/main.rs | 12 +++++----- 4 files changed, 44 insertions(+), 61 deletions(-) diff --git a/src/commands/db.rs b/src/commands/db.rs index 672a0d6..e984848 100644 --- a/src/commands/db.rs +++ b/src/commands/db.rs @@ -33,12 +33,11 @@ use log::trace; use crate::commands::util::get_date_filter; use crate::config::Configuration; -use crate::db::DbConnectionConfig; use crate::db::models; +use crate::db::DbConnectionConfig; use crate::log::JobResult; use crate::package::Script; use crate::schema; -use crate::util::progress::ProgressBars; diesel_migrations::embed_migrations!("migrations"); @@ -47,20 +46,19 @@ pub fn db( db_connection_config: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches, - progressbars: ProgressBars, ) -> Result<()> { match matches.subcommand() { Some(("cli", matches)) => cli(db_connection_config, matches), - Some(("setup", _matches)) => setup(db_connection_config, progressbars), - Some(("artifacts", matches)) => artifacts(db_connection_config, matches, progressbars), - Some(("envvars", matches)) => envvars(db_connection_config, matches, progressbars), - Some(("images", matches)) => images(db_connection_config, matches, progressbars), - Some(("submit", matches)) => submit(db_connection_config, matches, progressbars), - Some(("submits", matches)) => submits(db_connection_config, matches, progressbars), - Some(("jobs", matches)) => jobs(db_connection_config, matches, progressbars), - Some(("job", matches)) => job(db_connection_config, config, matches, progressbars), - Some(("log-of", matches)) => log_of(db_connection_config, matches, progressbars), - Some(("releases", matches)) => releases(db_connection_config, config, matches, progressbars), + Some(("setup", _matches)) => setup(db_connection_config), + Some(("artifacts", matches)) => artifacts(db_connection_config, matches), + Some(("envvars", matches)) => envvars(db_connection_config, matches), + Some(("images", matches)) => images(db_connection_config, matches), + Some(("submit", matches)) => submit(db_connection_config, matches), + Some(("submits", matches)) => submits(db_connection_config, matches), + Some(("jobs", matches)) => jobs(db_connection_config, matches), + Some(("job", matches)) => job(db_connection_config, config, matches), + Some(("log-of", matches)) => log_of(db_connection_config, matches), + Some(("releases", matches)) => releases(db_connection_config, config, matches), Some((other, _)) => Err(anyhow!("Unknown subcommand: {}", other)), None => Err(anyhow!("No subcommand")), } @@ -150,18 +148,18 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re .run_for_uri(db_connection_config) } -fn setup(conn_cfg: DbConnectionConfig<'_>, progressbars: ProgressBars) -> Result<()> { - let conn = conn_cfg.establish_connection(&progressbars)?; +fn setup(conn_cfg: DbConnectionConfig<'_>) -> Result<()> { + let conn = conn_cfg.establish_connection()?; embedded_migrations::run_with_output(&conn, &mut std::io::stdout()).map_err(Error::from) } /// Implementation of the "db artifacts" subcommand -fn artifacts(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn artifacts(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { use crate::schema::artifacts::dsl; let csv = matches.is_present("csv"); let hdrs = crate::commands::util::mk_header(vec!["Path", "Released", "Job"]); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let data = matches .value_of("job_uuid") .map(uuid::Uuid::parse_str) @@ -205,12 +203,12 @@ fn artifacts(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbar } /// Implementation of the "db envvars" subcommand -fn envvars(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn envvars(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { use crate::schema::envvars::dsl; let csv = matches.is_present("csv"); let hdrs = crate::commands::util::mk_header(vec!["Name", "Value"]); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let data = dsl::envvars .load::(&conn)? .into_iter() @@ -227,12 +225,12 @@ fn envvars(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: } /// Implementation of the "db images" subcommand -fn images(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn images(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { use crate::schema::images::dsl; let csv = matches.is_present("csv"); let hdrs = crate::commands::util::mk_header(vec!["Name"]); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let data = dsl::images .load::(&conn)? .into_iter() @@ -249,8 +247,8 @@ fn images(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: } /// Implementation of the "db submit" subcommand -fn submit(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { - let conn = conn_cfg.establish_connection(&progressbars)?; +fn submit(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { + let conn = conn_cfg.establish_connection()?; let submit_id = matches.value_of("submit") .map(uuid::Uuid::from_str) .transpose() @@ -333,11 +331,11 @@ fn submit(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: } /// Implementation of the "db submits" subcommand -fn submits(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn submits(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { let csv = matches.is_present("csv"); let limit = matches.value_of("limit").map(i64::from_str).transpose()?; let hdrs = crate::commands::util::mk_header(vec!["Time", "UUID"]); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let query = schema::submits::table .order_by(schema::submits::id.desc()); // required for the --limit implementation @@ -399,7 +397,7 @@ fn submits(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: } /// Implementation of the "db jobs" subcommand -fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { let csv = matches.is_present("csv"); let hdrs = crate::commands::util::mk_header(vec![ "Submit", @@ -410,7 +408,7 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: Pr "Package", "Version", ]); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let older_than_filter = get_date_filter("older_than", matches)?; let newer_than_filter = get_date_filter("newer_than", matches)?; @@ -497,14 +495,14 @@ fn jobs(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: Pr } /// Implementation of the "db job" subcommand -fn job(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn job(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches) -> Result<()> { let script_highlight = !matches.is_present("no_script_highlight"); let script_line_numbers = !matches.is_present("no_script_line_numbers"); let configured_theme = config.script_highlight_theme(); let show_log = matches.is_present("show_log"); let show_script = matches.is_present("show_script"); let csv = matches.is_present("csv"); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let job_uuid = matches .value_of("job_uuid") .map(uuid::Uuid::parse_str) @@ -671,8 +669,8 @@ fn job(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMa } /// Implementation of the subcommand "db log-of" -fn log_of(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { - let conn = conn_cfg.establish_connection(&progressbars)?; +fn log_of(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches) -> Result<()> { + let conn = conn_cfg.establish_connection()?; let job_uuid = matches .value_of("job_uuid") .map(uuid::Uuid::parse_str) @@ -694,9 +692,9 @@ fn log_of(conn_cfg: DbConnectionConfig<'_>, matches: &ArgMatches, progressbars: } /// Implementation of the "db releases" subcommand -fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches, progressbars: ProgressBars) -> Result<()> { +fn releases(conn_cfg: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches) -> Result<()> { let csv = matches.is_present("csv"); - let conn = conn_cfg.establish_connection(&progressbars)?; + let conn = conn_cfg.establish_connection()?; let header = crate::commands::util::mk_header(["Package", "Version", "Date", "Path"].to_vec()); let mut query = schema::jobs::table .inner_join(schema::packages::table) diff --git a/src/commands/release.rs b/src/commands/release.rs index 12decff..6f0232b 100644 --- a/src/commands/release.rs +++ b/src/commands/release.rs @@ -22,20 +22,18 @@ use log::{debug, info, trace}; use tokio_stream::StreamExt; use crate::config::Configuration; -use crate::db::DbConnectionConfig; use crate::db::models as dbmodels; -use crate::util::progress::ProgressBars; +use crate::db::DbConnectionConfig; /// Implementation of the "release" subcommand pub async fn release( db_connection_config: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches, - progressbars: ProgressBars, ) -> Result<()> { match matches.subcommand() { - Some(("new", matches)) => new_release(db_connection_config, config, matches, progressbars).await, - Some(("rm", matches)) => rm_release(db_connection_config, config, matches, progressbars).await, + Some(("new", matches)) => new_release(db_connection_config, config, matches).await, + Some(("rm", matches)) => rm_release(db_connection_config, config, matches).await, Some((other, _matches)) => Err(anyhow!("Unknown subcommand: {}", other)), None => Err(anyhow!("Missing subcommand")), } @@ -46,7 +44,6 @@ async fn new_release( db_connection_config: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches, - progressbars: ProgressBars, ) -> Result<()> { let print_released_file_pathes = !matches.is_present("quiet"); let release_store_name = matches.value_of("release_store_name").unwrap(); // safe by clap @@ -63,7 +60,7 @@ async fn new_release( debug!("Release called for: {:?} {:?}", pname, pvers); - let conn = db_connection_config.establish_connection(&progressbars)?; + let conn = db_connection_config.establish_connection()?; let submit_uuid = matches .value_of("submit_uuid") .map(uuid::Uuid::parse_str) @@ -196,7 +193,6 @@ pub async fn rm_release( db_connection_config: DbConnectionConfig<'_>, config: &Configuration, matches: &ArgMatches, - progressbars: ProgressBars, ) -> Result<()> { let release_store_name = matches.value_of("release_store_name").map(String::from).unwrap(); // safe by clap if !(config.releases_directory().exists() && config.releases_directory().is_dir()) { @@ -213,7 +209,7 @@ pub async fn rm_release( let pvers = matches.value_of("package_version").map(String::from).unwrap(); // safe by clap debug!("Remove Release called for: {:?} {:?}", pname, pvers); - let conn = db_connection_config.establish_connection(&progressbars)?; + let conn = db_connection_config.establish_connection()?; let (release, artifact) = crate::schema::jobs::table .inner_join(crate::schema::packages::table) diff --git a/src/db/connection.rs b/src/db/connection.rs index 76d38c1..cf9a0c0 100644 --- a/src/db/connection.rs +++ b/src/db/connection.rs @@ -19,7 +19,6 @@ use getset::Getters; use log::debug; use crate::config::Configuration; -use crate::util::progress::ProgressBars; #[derive(Getters)] pub struct DbConnectionConfig<'a> { @@ -79,7 +78,7 @@ impl<'a> DbConnectionConfig<'a> { }) } - pub fn establish_connection(self, progressbars: &ProgressBars) -> Result { + pub fn establish_connection(self) -> Result { debug!("Trying to connect to database: {:?}", self); let database_uri: String = format!( "postgres://{user}:{password}@{host}:{port}/{name}?connect_timeout={timeout}", @@ -90,17 +89,7 @@ impl<'a> DbConnectionConfig<'a> { name = self.database_name, timeout = self.database_connection_timeout, ); - - let bar = progressbars.spinner(); - bar.set_message("Establishing database connection"); - - let conn = PgConnection::establish(&database_uri).map_err(Error::from); - if conn.is_err() { - bar.finish_with_message("Connection could not be established"); - } else { - bar.finish_with_message("Connection established"); - } - conn + PgConnection::establish(&database_uri).map_err(Error::from) } } diff --git a/src/main.rs b/src/main.rs index 18dee07..3ddce14 100644 --- a/src/main.rs +++ b/src/main.rs @@ -152,9 +152,9 @@ async fn main() -> Result<()> { let db_connection_config = crate::db::DbConnectionConfig::parse(&config, &cli)?; match cli.subcommand() { Some(("generate-completions", matches)) => generate_completions(matches), - Some(("db", matches)) => crate::commands::db(db_connection_config, &config, matches, progressbars)?, + Some(("db", matches)) => crate::commands::db(db_connection_config, &config, matches)?, Some(("build", matches)) => { - let conn = db_connection_config.establish_connection(&progressbars)?; + let conn = db_connection_config.establish_connection()?; let repo = load_repo()?; @@ -200,7 +200,7 @@ async fn main() -> Result<()> { Some(("find-artifact", matches)) => { let repo = load_repo()?; - let conn = db_connection_config.establish_connection(&progressbars)?; + let conn = db_connection_config.establish_connection()?; crate::commands::find_artifact(matches, &config, progressbars, repo, conn) .await .context("find-artifact command failed")? @@ -221,7 +221,7 @@ async fn main() -> Result<()> { } Some(("release", matches)) => { - crate::commands::release(db_connection_config, &config, matches, progressbars) + crate::commands::release(db_connection_config, &config, matches) .await .context("release command failed")? } @@ -242,8 +242,8 @@ async fn main() -> Result<()> { Some(("metrics", _)) => { let repo = load_repo()?; - let conn = db_connection_config.establish_connection(&progressbars)?; - crate::commands::metrics(repo_path, &config, repo, conn) + let conn = db_connection_config.establish_connection()?; + crate::commands::metrics(&repo_path, &config, repo, conn) .await .context("metrics command failed")? } -- cgit v1.2.3