Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

queue connection_gateway messages (#1534)

Eric Hayesc2ae9c74b7ea
diff --git a/infra/stacks/document-cognition-service/index.ts b/infra/stacks/document-cognition-service/index.ts
index 5df3785433..f0dbf95914 100644
--- a/infra/stacks/document-cognition-service/index.ts
+++ b/infra/stacks/document-cognition-service/index.ts
@@ -324,7 +324,7 @@ const documentCognitionService = new DocumentCognitionService(
value: AUTHENTICATION_SERVICE_INTERNAL_API_KEY_SECRET_NAME,
},
{
- name: 'REDIS_URL',
+ name: 'REDIS_HOST',
value: pulumi.interpolate`redis://${connectionGatewayRedisUrl}`,
},
// OpenTelemetry / Datadog tracing configuration
diff --git a/js/app/packages/service-clients/service-connection/websocket.ts b/js/app/packages/service-clients/service-connection/websocket.ts
index 7ca9c38556..7d12a5109b 100644
--- a/js/app/packages/service-clients/service-connection/websocket.ts
+++ b/js/app/packages/service-clients/service-connection/websocket.ts
@@ -5,6 +5,7 @@ import { fetchToken, unsetTokenPromise } from '@core/util/fetchWithToken';
import { getMacroApiToken } from '@service-auth/fetch';
import { createCallback } from '@solid-primitives/rootless';
import {
+ ArrayQueue,
createSocketEffect,
JsonSerializer,
LinearBackoff,
@@ -43,6 +44,7 @@ export const ws = new WebsocketBuilder(resolveWsUrl)
.withSerializer(
new JsonSerializer<ToWebsocketMessage, FromWebsocketMessage>()
)
+ .withBuffer(new ArrayQueue())
.withBackoff(new LinearBackoff(500, 500))
.withMaxRetries(20)
.withHeartbeat({
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 64550d72c4..94e07e4321 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -2693,6 +2693,7 @@ dependencies = [
"macro_db_migrator",
"macro_entrypoint",
"macro_env",
+ "macro_env_var",
"macro_middleware",
"macro_project_utils",
"macro_share_permissions",
diff --git a/rust/cloud-storage/document_cognition_service/Cargo.toml b/rust/cloud-storage/document_cognition_service/Cargo.toml
index d7b3779481..663753a750 100644
--- a/rust/cloud-storage/document_cognition_service/Cargo.toml
+++ b/rust/cloud-storage/document_cognition_service/Cargo.toml
@@ -64,6 +64,7 @@ macro_cors = { path = "../macro_cors" }
macro_db_client = { path = "../macro_db_client" }
macro_entrypoint = { path = "../macro_entrypoint" }
macro_env = { path = "../macro_env" }
+macro_env_var = { path = "../macro_env_var" }
macro_middleware = { path = "../macro_middleware", default-features = false, features = [
"auth",
"cloud_storage",
diff --git a/rust/cloud-storage/document_cognition_service/src/config.rs b/rust/cloud-storage/document_cognition_service/src/config.rs
index 83e9cd739d..6ce316bd1e 100644
--- a/rust/cloud-storage/document_cognition_service/src/config.rs
+++ b/rust/cloud-storage/document_cognition_service/src/config.rs
@@ -1,5 +1,6 @@
use anyhow::Context;
pub use macro_env::Environment;
+use macro_env_var::env_var;
use crate::core::constants::DEFAULT_DOCUMENT_BATCH_LIMIT;
/// The configuration parameters for the application.
@@ -9,7 +10,6 @@ use crate::core::constants::DEFAULT_DOCUMENT_BATCH_LIMIT;
/// populate the Docker container
///
/// See `.env.sample` in cognitive-workspace root for details.
-#[derive(Debug)]
pub struct Config {
/// The connection URL for the Postgres database this application should use.
pub database_url: String,
@@ -42,13 +42,19 @@ pub struct Config {
pub authentication_service_url: String,
/// authentication service secret key (for soup service)
pub authentication_service_secret_key: String,
- /// Redis URL for stream service
- pub redis_url: String,
+ /// Redis host for stream service
+ pub redis_host: RedisHost,
}
+env_var!(
+ pub struct EnvVars {
+ pub RedisHost,
+ }
+);
+
impl Config {
- #[tracing::instrument(err)]
- pub fn from_env() -> anyhow::Result<Self> {
+ #[tracing::instrument(err, skip_all)]
+ pub fn from_env(env_vars: EnvVars) -> anyhow::Result<Self> {
let database_url =
std::env::var("DATABASE_URL").context("DATABASE_URL must be provided")?;
let port: usize = std::env::var("PORT")
@@ -103,7 +109,7 @@ impl Config {
let authentication_service_secret_key = std::env::var("AUTHENTICATION_SERVICE_SECRET_KEY")
.context("AUTHENTICATION_SERVICE_SECRET_KEY must be provided")?;
- let redis_url = std::env::var("REDIS_URL").context("REDIS_URL must be provided")?;
+ let EnvVars { redis_host } = env_vars;
Ok(Config {
database_url,
@@ -124,7 +130,7 @@ impl Config {
static_file_service_url,
authentication_service_url,
authentication_service_secret_key,
- redis_url,
+ redis_host,
})
}
@@ -149,7 +155,7 @@ impl Config {
static_file_service_url: Default::default(),
authentication_service_url: Default::default(),
authentication_service_secret_key: Default::default(),
- redis_url: Default::default(),
+ redis_host: RedisHost::Comptime("redis://localhost:6379"),
}
}
}
diff --git a/rust/cloud-storage/document_cognition_service/src/main.rs b/rust/cloud-storage/document_cognition_service/src/main.rs
index 5e080cf81a..47ea0ad0e6 100644
--- a/rust/cloud-storage/document_cognition_service/src/main.rs
+++ b/rust/cloud-storage/document_cognition_service/src/main.rs
@@ -4,7 +4,7 @@ use comms::domain::service::ChannelServiceImpl;
use comms::outbound::http::user_repo::UserRepoImpl;
use comms::outbound::postgres::comms_repo::PgCommsRepo;
use comms_service_client::CommsServiceClient;
-use config::{Config, Environment};
+use config::{Config, EnvVars, Environment};
use document_cognition_service_client::DocumentCognitionServiceClient;
use document_storage_service_client::DocumentStorageServiceClient;
use email::domain::service::EmailServiceImpl;
@@ -38,7 +38,8 @@ async fn main() -> anyhow::Result<()> {
MacroEntrypoint::default().init();
// Parse our configuration from the environment.
- let config = Config::from_env().context("failed to parse config from environment")?;
+ let config = Config::from_env(EnvVars::unwrap_new())
+ .context("failed to parse config from environment")?;
tracing::info!("initialized config");
@@ -173,11 +174,23 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("initialized soup service");
// Initialize Redis client for stream service
- let redis_client =
- redis::Client::open(config.redis_url.as_str()).context("failed to create redis client")?;
- let stream_repo = RedisStreamRepo::new(redis_client)
+ let redis_client = Arc::new(
+ redis::Client::open(config.redis_host.as_ref())
+ .inspect(|client| {
+ client
+ .get_connection()
+ .map(|_| tracing::trace!("initialized redis connection"))
+ .inspect_err(|e| {
+ tracing::error!(error=?e, "failed to connect to redis");
+ })
+ .expect("redis connetion required");
+ })
+ .context("failed to connect to redis")?,
+ );
+
+ let stream_repo = RedisStreamRepo::new((*redis_client).clone())
.await
- .map_err(|e| anyhow::anyhow!("failed to create stream repo: {}", e))?
+ .context("failed to create stream repo")?
.obj();
tracing::info!("initialized stream repo");