From 30dfe649aef5a5cfed333f21b36ea8b7bb88d00a Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 13 Jun 2021 03:02:35 -0400 Subject: [PATCH] configure redis with env var --- src/main.rs | 13 ++++++++++--- src/shared_constants.rs | 8 ++++++-- src/tts_download_job.rs | 4 ++-- src/tts_inference_job.rs | 4 ++-- src/w2l_download_job.rs | 4 ++-- src/w2l_inference_job.rs | 4 ++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 40ad895615..964e449103 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,9 @@ use crate::http_server::endpoints::w2l::set_w2l_template_mod_approval::set_w2l_t use crate::http_server::web_utils::cookie_manager::CookieManager; use crate::http_server::web_utils::session_checker::SessionChecker; use crate::server_state::{ServerState, EnvConfig}; -use crate::shared_constants::{DEFAULT_RUST_LOG, DEFAULT_MYSQL_PASSWORD}; +use crate::shared_constants::DEFAULT_MYSQL_CONNECTION_STRING; +use crate::shared_constants::DEFAULT_REDIS_CONNECTION_STRING; +use crate::shared_constants::DEFAULT_RUST_LOG; use crate::util::encrypted_sort_id::SortKeyCrypto; use log::{info}; use r2d2_redis::RedisConnectionManager; @@ -141,7 +143,12 @@ async fn main() -> AnyhowResult<()> { let db_connection_string = easyenv::get_env_string_or_default( "MYSQL_URL", - DEFAULT_MYSQL_PASSWORD); + DEFAULT_MYSQL_CONNECTION_STRING); + + let redis_connection_string = + easyenv::get_env_string_or_default( + "REDIS_URL", + DEFAULT_REDIS_CONNECTION_STRING); let pool = MySqlPoolOptions::new() .max_connections(5) @@ -152,7 +159,7 @@ async fn main() -> AnyhowResult<()> { mysql_pool: pool.clone(), // NB: Pool is clone/sync/send-safe }; - let redis_manager = RedisConnectionManager::new("redis://localhost")?; + let redis_manager = RedisConnectionManager::new(redis_connection_string)?; let redis_pool = r2d2::Pool::builder() .build(redis_manager)?; diff --git a/src/shared_constants.rs b/src/shared_constants.rs index fdf33c4087..a562d9e317 100644 --- a/src/shared_constants.rs +++ b/src/shared_constants.rs @@ -1,12 +1,16 @@ //! Shared constants that all binaries use. +//! Or at least that deserve extremely high visibility. /// NB: `sqlx::query` is spammy and dumps all queries as "info"-level log lines. /// NB: `hyper::proto::h1::io` is incredibly spammy and logs every chunk of bytes in very large files being downloaded. pub const DEFAULT_RUST_LOG: &'static str = "debug,actix_web=info,sqlx::query=warn,hyper::proto::h1::io=warn"; //const DEFAULT_RUST_LOG: &'static str = "debug,actix_web=info"; // but sometimes we want to debug -/// The default MySql password for use in development -pub const DEFAULT_MYSQL_PASSWORD: &'static str = "mysql://storyteller:password@localhost/storyteller"; +/// The default Redis connection string for use in development +pub const DEFAULT_REDIS_CONNECTION_STRING: &'static str = "redis://localhost"; + +/// The default MySql connection string for use in development +pub const DEFAULT_MYSQL_CONNECTION_STRING: &'static str = "mysql://storyteller:password@localhost/storyteller"; /// The number of results we return by default for paginated queries. pub const DEFAULT_MYSQL_QUERY_RESULT_PAGE_SIZE: u16 = 25; diff --git a/src/tts_download_job.rs b/src/tts_download_job.rs index 4776c6b04f..9de093df57 100644 --- a/src/tts_download_job.rs +++ b/src/tts_download_job.rs @@ -41,7 +41,7 @@ use crate::util::random_crockford_token::random_crockford_token; use data_encoding::{HEXUPPER, HEXLOWER, HEXLOWER_PERMISSIVE}; use log::{warn, info}; use ring::digest::{Context, Digest, SHA256}; -use shared_constants::DEFAULT_MYSQL_PASSWORD; +use shared_constants::DEFAULT_MYSQL_CONNECTION_STRING; use shared_constants::DEFAULT_RUST_LOG; use sqlx::MySqlPool; use sqlx::mysql::MySqlPoolOptions; @@ -136,7 +136,7 @@ async fn main() -> AnyhowResult<()> { let db_connection_string = easyenv::get_env_string_or_default( "MYSQL_URL", - DEFAULT_MYSQL_PASSWORD); + DEFAULT_MYSQL_CONNECTION_STRING); info!("Connecting to database..."); diff --git a/src/tts_inference_job.rs b/src/tts_inference_job.rs index f0a3ab747f..9d848ed5a2 100644 --- a/src/tts_inference_job.rs +++ b/src/tts_inference_job.rs @@ -44,7 +44,7 @@ use crate::util::semi_persistent_cache_dir::SemiPersistentCacheDir; use data_encoding::{HEXUPPER, HEXLOWER, HEXLOWER_PERMISSIVE}; use log::{warn, info}; use ring::digest::{Context, Digest, SHA256}; -use shared_constants::DEFAULT_MYSQL_PASSWORD; +use shared_constants::DEFAULT_MYSQL_CONNECTION_STRING; use shared_constants::DEFAULT_RUST_LOG; use sqlx::MySqlPool; use sqlx::mysql::MySqlPoolOptions; @@ -160,7 +160,7 @@ async fn main() -> AnyhowResult<()> { let db_connection_string = easyenv::get_env_string_or_default( "MYSQL_URL", - DEFAULT_MYSQL_PASSWORD); + DEFAULT_MYSQL_CONNECTION_STRING); info!("Connecting to database..."); diff --git a/src/w2l_download_job.rs b/src/w2l_download_job.rs index 6d95c6c410..fe56a03218 100644 --- a/src/w2l_download_job.rs +++ b/src/w2l_download_job.rs @@ -44,7 +44,7 @@ use crate::util::random_crockford_token::random_crockford_token; use data_encoding::{HEXUPPER, HEXLOWER, HEXLOWER_PERMISSIVE}; use log::{warn, info}; use ring::digest::{Context, Digest, SHA256}; -use shared_constants::DEFAULT_MYSQL_PASSWORD; +use shared_constants::DEFAULT_MYSQL_CONNECTION_STRING; use shared_constants::DEFAULT_RUST_LOG; use sqlx::MySqlPool; use sqlx::mysql::MySqlPoolOptions; @@ -183,7 +183,7 @@ async fn main() -> AnyhowResult<()> { let db_connection_string = easyenv::get_env_string_or_default( "MYSQL_URL", - DEFAULT_MYSQL_PASSWORD); + DEFAULT_MYSQL_CONNECTION_STRING); info!("Connecting to database..."); diff --git a/src/w2l_inference_job.rs b/src/w2l_inference_job.rs index 4bb423073b..082b237b26 100644 --- a/src/w2l_inference_job.rs +++ b/src/w2l_inference_job.rs @@ -46,7 +46,7 @@ use crate::util::semi_persistent_cache_dir::SemiPersistentCacheDir; use data_encoding::{HEXUPPER, HEXLOWER, HEXLOWER_PERMISSIVE}; use log::{warn, info}; use ring::digest::{Context, Digest, SHA256}; -use shared_constants::DEFAULT_MYSQL_PASSWORD; +use shared_constants::DEFAULT_MYSQL_CONNECTION_STRING; use shared_constants::DEFAULT_RUST_LOG; use sqlx::MySqlPool; use sqlx::mysql::MySqlPoolOptions; @@ -179,7 +179,7 @@ async fn main() -> AnyhowResult<()> { let db_connection_string = easyenv::get_env_string_or_default( "MYSQL_URL", - DEFAULT_MYSQL_PASSWORD); + DEFAULT_MYSQL_CONNECTION_STRING); info!("Connecting to database...");