Skip to content

Commit

Permalink
Add logging for startup
Browse files Browse the repository at this point in the history
  • Loading branch information
tazz4843 committed May 16, 2024
1 parent 4e1b4c8 commit 05d0552
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
19 changes: 15 additions & 4 deletions scripty_bot_utils/src/voice_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,26 @@ async fn internal_handle_message(
let lang = res.language;
let translate = res.translate;

let max_duration = output_length_secs * 2.0;
new_msg
.edit(
&ctx,
EditMessage::new().content(format!(
"Transcribing voice message...\nThis should take no longer than {} seconds +- 1 \
second.",
max_duration
)),
)
.await?;
let stream = scripty_stt::get_stream().await?;
stream.feed_audio(output)?;
debug!(%msg.id, "fed audio to speech-to-text, waiting up to {} seconds for result", output_length_secs * 2.0);
debug!(%msg.id, "fed audio to speech-to-text, waiting up to {} seconds for result", max_duration);
let transcript = stream
.get_result(
lang,
false,
translate,
Some(Duration::from_secs_f64(output_length_secs * 2.0)),
Some(Duration::from_secs_f64(max_duration)),
)
.await?;
let transcript = transcript.trim();
Expand Down Expand Up @@ -135,7 +146,7 @@ async fn internal_handle_message(
pub async fn voice_message_enabled_for_guild(guild: GuildId) -> bool {
// try to fetch from redis
let redis_res = scripty_redis::run_transaction::<Option<bool>>("GET", |cmd| {
cmd.arg(format!("msg_transcript_{}", guild.get()));
cmd.arg(format!("voice_msg_transcript_ {}", guild.get()));
})
.await
.unwrap_or_else(|e| {
Expand All @@ -160,7 +171,7 @@ pub async fn voice_message_enabled_for_guild(guild: GuildId) -> bool {

// cache in redis
if let Err(e) = scripty_redis::run_transaction::<()>("SETEX", |cmd| {
cmd.arg(format!("msg_transcript_{}", guild.get()))
cmd.arg(format!("voice_msg_transcript_{}", guild.get()))
.arg(60 * 60 * 3)
.arg(ret);
})
Expand Down
4 changes: 2 additions & 2 deletions scripty_data_storage/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use voice::{change_voice_state, get_voice_state};

/// Optionally load all users in database into cache
pub async fn init_cache_async() -> Result<(), scripty_redis::redis::RedisError> {
text::init_text_cache_async().await?;
voice::init_voice_cache_async().await?;
// text::init_text_cache_async().await?;
// voice::init_voice_cache_async().await?;
Ok(())
}
2 changes: 2 additions & 0 deletions scripty_db/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ pub async fn init_db() {
DatabaseConnection::Unix(path) => conn_opts.socket(path),
};

info!("trying to connect to postgres");
let pool = PgPoolOptions::new()
.min_connections(2)
.max_connections(32)
.connect_with(conn_opts)
.await
.expect("failed to connect to db");

info!("running pending migrations");
sqlx::migrate!("../migrations")
.run(&pool)
.await
Expand Down
3 changes: 3 additions & 0 deletions scripty_db/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[macro_use]
extern crate tracing;

mod init;
mod store;

Expand Down
4 changes: 4 additions & 0 deletions scripty_redis/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use deadpool::managed::{PoolConfig, QueueMode, Timeouts};
use deadpool_redis::{redis::cmd, Config, Runtime};

pub async fn init_redis() {
info!("configuring redis pool");

// set up pool config
let mut config = Config::from_url(&scripty_config::get_config().redis_url);
let mut timeouts = Timeouts::new();
Expand All @@ -17,11 +19,13 @@ pub async fn init_redis() {
});

// initialize the pool
info!("connecting to redis server");
let pool = config
.create_pool(Some(Runtime::Tokio1))
.expect("failed to init redis");

// test the pool by setting a key and getting it, then deleting it
info!("testing connection");
let mut conn = pool.get().await.unwrap();
let _: () = cmd("SET")
.arg("test")
Expand Down
3 changes: 3 additions & 0 deletions scripty_redis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! General wrapper around Redis.
#[macro_use]
extern crate tracing;

mod init;
mod transaction;

Expand Down
2 changes: 2 additions & 0 deletions scripty_stt/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::load_balancer::LoadBalancer;

pub async fn init_stt() {
info!("starting stt load balancer");

let balancer = LoadBalancer::new()
.await
.expect("failed to initialize a STT service");
Expand Down

0 comments on commit 05d0552

Please sign in to comment.