Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
refactor(connection_gateway): use single redis connection (#1912)
Will Hutchinson51a9896e456d
diff --git a/rust/cloud-storage/connection_gateway/src/api/message/mod.rs b/rust/cloud-storage/connection_gateway/src/api/message/mod.rsindex b22d03b28f..e9f048e4e8 100644--- a/rust/cloud-storage/connection_gateway/src/api/message/mod.rs+++ b/rust/cloud-storage/connection_gateway/src/api/message/mod.rs@@ -55,17 +55,7 @@ pub async fn send_message_handler(Path(entity): Path<Entity<'static>>,Json(body): Json<SendMessageBody>,) -> Result<(StatusCode, JsonResponse<SendMessageResponse>), (StatusCode, String)> {- let redis_connection = ctx- .context- .get_multiplexed_async_connection()- .await- .map_err(|e| {- tracing::error!(error=?e, "unable to get redis connection");- (- StatusCode::INTERNAL_SERVER_ERROR,- "unable to send message".to_string(),- )- })?;+ let redis_connection = ctx.context.redis_connection.clone();let res = send_message_to_entity(&ctx,@@ -107,17 +97,7 @@ pub async fn batch_send_message_handler() -> Result<(StatusCode, JsonResponse<SendMessageResponse>), (StatusCode, String)> {let now = Instant::now();- let redis_connection = ctx- .context- .get_multiplexed_async_connection()- .await- .map_err(|e| {- tracing::error!(error=?e, "unable to get redis connection");- (- StatusCode::INTERNAL_SERVER_ERROR,- "unable to send message".to_string(),- )- })?;+ let redis_connection = ctx.context.redis_connection.clone();let all_receipts = try_join_all(body.entities.iter().map(|entity| {let redis_connection = redis_connection.clone();@@ -168,17 +148,7 @@ pub async fn batch_send_unique_messages_handler() -> Result<(StatusCode, JsonResponse<SendMessageResponse>), (StatusCode, String)> {let now = Instant::now();- let redis_connection = ctx- .context- .get_multiplexed_async_connection()- .await- .map_err(|e| {- tracing::error!(error=?e, "unable to get redis connection");- (- StatusCode::INTERNAL_SERVER_ERROR,- "unable to send message".to_string(),- )- })?;+ let redis_connection = ctx.context.redis_connection.clone();let all_receipts = try_join_all(body.messages.iter().map(|message| {let redis_connection = redis_connection.clone();diff --git a/rust/cloud-storage/connection_gateway/src/context.rs b/rust/cloud-storage/connection_gateway/src/context.rsindex 8eb32b807e..6d4e9075e7 100644--- a/rust/cloud-storage/connection_gateway/src/context.rs+++ b/rust/cloud-storage/connection_gateway/src/context.rs@@ -18,16 +18,14 @@ pub struct ApiContext {pub connection_manager: crate::service::connection::ConnectionManager,pub frecency_ingestor_service: EventIngestorImpl<FrecencyPgStorage>,pub redis_client: Arc<redis::Client>,+ pub redis_connection: MultiplexedConnection,pub stream_manager: Arc<dyn StreamManager + Send + Sync>,pub last_online_worker: Arc<LastOnlineWorker>,}impl ApiContext {- #[tracing::instrument(err, skip(self))]- pub async fn get_multiplexed_async_connection(- &self,- ) -> Result<MultiplexedConnection, RedisError> {- self.redis_client.get_multiplexed_async_connection().await+ pub fn get_multiplexed_async_connection(&self) -> Result<MultiplexedConnection, RedisError> {+ Ok(self.redis_connection.clone())}}diff --git a/rust/cloud-storage/connection_gateway/src/main.rs b/rust/cloud-storage/connection_gateway/src/main.rsindex 6a6670a849..23935b5eba 100644--- a/rust/cloud-storage/connection_gateway/src/main.rs+++ b/rust/cloud-storage/connection_gateway/src/main.rs@@ -92,10 +92,13 @@ async fn main() -> Result<()> {let connection_manager = create_dynamo_db_connection_manager(dynamodb_client.clone()).await?;- let last_online_redis_conn = redis_client.get_multiplexed_async_connection().await?;+ let redis_connection = redis_client+ .get_multiplexed_async_connection()+ .await+ .context("failed to create shared redis connection")?;let last_online_worker = Arc::new(LastOnlineWorker::new(LastOnlineService::new(LastOnlineDefaultTime,- RedisLastOnlineRepo::new(last_online_redis_conn),+ RedisLastOnlineRepo::new(redis_connection.clone()),)));let pgpool = PgPoolOptions::new().min_connections(3)@@ -116,6 +119,7 @@ async fn main() -> Result<()> {let context = context::ApiContext {connection_manager,redis_client: Arc::clone(&redis_client),+ redis_connection,frecency_ingestor_service: EventIngestorImpl::new(FrecencyPgStorage::new(pgpool.clone())),stream_manager,last_online_worker,diff --git a/rust/cloud-storage/connection_gateway/src/service/tracker.rs b/rust/cloud-storage/connection_gateway/src/service/tracker.rsindex a8fe345173..ecf57484ec 100644--- a/rust/cloud-storage/connection_gateway/src/service/tracker.rs+++ b/rust/cloud-storage/connection_gateway/src/service/tracker.rs@@ -156,7 +156,7 @@ pub async fn notify_tracking_change(ctx: ConnectionContext<'_>, entity: &Entity<})?,};- let redis_connection = ctx.api_context.get_multiplexed_async_connection().await?;+ let redis_connection = ctx.api_context.redis_connection.clone();send_message_to_entity(ctx, entity, message, redis_connection).await?;Ok(())