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.

feat(sync): add bulk fire and forget wake up call to sync service (#3042)

teo5ee3fe52703f
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/bulkWakeupRequest.ts b/js/app/packages/service-clients/service-storage/generated/schemas/bulkWakeupRequest.ts
new file mode 100644
index 0000000000..e907cc0c84
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/bulkWakeupRequest.ts
@@ -0,0 +1,10 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export interface BulkWakeupRequest {
+ document_ids: string[];
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/bulkWakeupResponse.ts b/js/app/packages/service-clients/service-storage/generated/schemas/bulkWakeupResponse.ts
new file mode 100644
index 0000000000..504a99667e
--- /dev/null
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/bulkWakeupResponse.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export interface BulkWakeupResponse {
+ /** @minimum 0 */
+ dispatched: number;
+}
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
index 936d544692..bb9959b43d 100644
--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts
@@ -78,6 +78,8 @@ export * from './basicDocumentSubTypeProperty';
export * from './basicDocumentType';
export * from './basicDocumentUpdatedAt';
export * from './bomPart';
+export * from './bulkWakeupRequest';
+export * from './bulkWakeupResponse';
export * from './callActiveResponse';
export * from './callFilters';
export * from './callFiltersAttended';
diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.ts
index 875f7da667..747c8149c2 100644
--- a/js/app/packages/service-clients/service-storage/generated/zod.ts
+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts
@@ -3893,6 +3893,10 @@ export const createInstructionsHandlerResponse = zod.object({
documentId: zod.string(),
});
+export const bulkWakeupSyncServiceDocumentsBody = zod.object({
+ document_ids: zod.array(zod.string()),
+});
+
/**
* @summary Gets the items the user has access to
*/
diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.json
index 4624377b8b..b46592f795 100644
--- a/js/app/packages/service-clients/service-storage/openapi.json
+++ b/js/app/packages/service-clients/service-storage/openapi.json
@@ -3807,6 +3807,40 @@
}
}
},
+ "/internal/sync_service/wakeup": {
+ "post": {
+ "tags": ["sync_service"],
+ "operationId": "bulk_wakeup_sync_service_documents",
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/BulkWakeupRequest"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "202": {
+ "description": "Wakeups accepted for fire-and-forget dispatch",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/BulkWakeupResponse"
+ }
+ }
+ }
+ },
+ "400": {
+ "description": "Malformed request or missing internal auth header"
+ },
+ "401": {
+ "description": "Invalid internal auth header"
+ }
+ }
+ }
+ },
"/items/soup": {
"get": {
"tags": ["soup::inbound::axum_router"],
@@ -6362,6 +6396,28 @@
}
}
},
+ "BulkWakeupRequest": {
+ "type": "object",
+ "required": ["document_ids"],
+ "properties": {
+ "document_ids": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ }
+ }
+ },
+ "BulkWakeupResponse": {
+ "type": "object",
+ "required": ["dispatched"],
+ "properties": {
+ "dispatched": {
+ "type": "integer",
+ "minimum": 0
+ }
+ }
+ },
"CallActiveResponse": {
"type": "object",
"description": "Response indicating whether an active call exists for a channel.",
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 2e09f00e08..8b17112726 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -3274,6 +3274,7 @@ dependencies = [
"sqlx",
"sqs_client",
"sqs_worker",
+ "sync_service",
"sync_service_client",
"system_properties",
"thiserror 2.0.17",
@@ -10993,6 +10994,15 @@ dependencies = [
"unicode-ident",
]
+[[package]]
+name = "sync_service"
+version = "0.1.0"
+dependencies = [
+ "axum",
+ "serde",
+ "utoipa",
+]
+
[[package]]
name = "sync_service_client"
version = "0.1.0"
@@ -11001,6 +11011,7 @@ dependencies = [
"model",
"reqwest 0.13.3",
"serde",
+ "sync_service",
"tokio",
"tracing",
]
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 427f9e2c89..3ca37d8ce1 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -129,6 +129,7 @@ members = [
"static_file",
"static_file_service",
"static_file_service_client",
+ "sync_service",
"sync_service_client",
"system_properties",
"teams",
diff --git a/rust/cloud-storage/document_storage_service/Cargo.toml b/rust/cloud-storage/document_storage_service/Cargo.toml
index f0ee5363a8..4b7974a51f 100644
--- a/rust/cloud-storage/document_storage_service/Cargo.toml
+++ b/rust/cloud-storage/document_storage_service/Cargo.toml
@@ -125,6 +125,7 @@ sqs_client = { path = "../sqs_client", default-features = false, features = [
] }
sqs_worker = { path = "../sqs_worker" }
sync_service_client = { path = "../sync_service_client" }
+sync_service_hex = { path = "../sync_service", package = "sync_service", features = ["inbound"] }
system_properties = { path = "../system_properties" }
thiserror = { workspace = true }
tokio = { workspace = true }
diff --git a/rust/cloud-storage/document_storage_service/src/api/mod.rs b/rust/cloud-storage/document_storage_service/src/api/mod.rs
index 97618c29dd..c2aeedba60 100644
--- a/rust/cloud-storage/document_storage_service/src/api/mod.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/mod.rs
@@ -226,6 +226,14 @@ fn api_router(state: ApiContext) -> Router {
search_service::search_router()
.with_state(SearchHandlerState::from_ref(&state)),
)
+ .nest(
+ "/sync_service",
+ sync_service_hex::inbound::axum_router::sync_service_router(
+ sync_service_hex::inbound::axum_router::SyncServiceRouterState {
+ service: state.sync_service_client.clone(),
+ },
+ ),
+ )
.layer(
ServiceBuilder::new()
.layer(axum::middleware::from_fn_with_state(
diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
index 7590816974..7770de0b3c 100644
--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs
+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs
@@ -243,7 +243,10 @@ use utoipa::OpenApi;
saved_views::exclude_default_view_handler,
// /github
- github::inbound::github_sync_router::install_sync_handler
+ github::inbound::github_sync_router::install_sync_handler,
+
+ // /internal/sync_service
+ sync_service_hex::inbound::axum_router::bulk_wakeup_handler
),
components(
schemas(
@@ -418,6 +421,10 @@ use utoipa::OpenApi;
CreateViewRequest,
ExcludeDefaultViewRequest,
ShortIdResponse,
+
+ // Sync service
+ sync_service_hex::domain::models::BulkWakeupRequest,
+ sync_service_hex::domain::models::BulkWakeupResponse,
),
),
tags(
diff --git a/rust/cloud-storage/sync_service/Cargo.toml b/rust/cloud-storage/sync_service/Cargo.toml
new file mode 100644
index 0000000000..ce055fe635
--- /dev/null
+++ b/rust/cloud-storage/sync_service/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+edition = "2024"
+name = "sync_service"
+publish = false
+version = "0.1.0"
+
+[features]
+default = []
+inbound = ["dep:axum", "dep:utoipa"]
+
+[dependencies]
+axum = { workspace = true, optional = true }
+serde = { workspace = true }
+utoipa = { workspace = true, optional = true }
diff --git a/rust/cloud-storage/sync_service/src/domain/mod.rs b/rust/cloud-storage/sync_service/src/domain/mod.rs
new file mode 100644
index 0000000000..0ff263963d
--- /dev/null
+++ b/rust/cloud-storage/sync_service/src/domain/mod.rs
@@ -0,0 +1,2 @@
+pub mod models;
+pub mod ports;
diff --git a/rust/cloud-storage/sync_service/src/domain/models.rs b/rust/cloud-storage/sync_service/src/domain/models.rs
new file mode 100644
index 0000000000..ac3bcf6e8b
--- /dev/null
+++ b/rust/cloud-storage/sync_service/src/domain/models.rs
@@ -0,0 +1,13 @@
+use serde::{Deserialize, Serialize};
+
+#[derive(Debug, Deserialize, Serialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+pub struct BulkWakeupRequest {
+ pub document_ids: Vec<String>,
+}
+
+#[derive(Debug, Deserialize, Serialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+pub struct BulkWakeupResponse {
+ pub dispatched: usize,
+}
diff --git a/rust/cloud-storage/sync_service/src/domain/ports.rs b/rust/cloud-storage/sync_service/src/domain/ports.rs
new file mode 100644
index 0000000000..2e26bbd20e
--- /dev/null
+++ b/rust/cloud-storage/sync_service/src/domain/ports.rs
@@ -0,0 +1,6 @@
+pub trait SyncWakeupService: Send + Sync + 'static {
+ /// Dispatch wakeups for the given documents and return the number accepted for dispatch.
+ ///
+ /// Implementations should not wait for sync-service responses.
+ fn bulk_wakeup(&self, document_ids: Vec<String>) -> usize;
+}
diff --git a/rust/cloud-storage/sync_service/src/inbound.rs b/rust/cloud-storage/sync_service/src/inbound.rs
new file mode 100644
index 0000000000..2021071c60
--- /dev/null
+++ b/rust/cloud-storage/sync_service/src/inbound.rs
@@ -0,0 +1 @@
+pub mod axum_router;
diff --git a/rust/cloud-storage/sync_service/src/inbound/axum_router.rs b/rust/cloud-storage/sync_service/src/inbound/axum_router.rs
new file mode 100644
index 0000000000..14c527b939
--- /dev/null
+++ b/rust/cloud-storage/sync_service/src/inbound/axum_router.rs
@@ -0,0 +1,64 @@
+use std::sync::Arc;
+
+use axum::{
+ Json, Router,
+ extract::State,
+ http::StatusCode,
+ response::{IntoResponse, Response},
+ routing::post,
+};
+
+use crate::domain::{
+ models::{BulkWakeupRequest, BulkWakeupResponse},
+ ports::SyncWakeupService,
+};
+
+pub struct SyncServiceRouterState<Svc> {
+ pub service: Arc<Svc>,
+}
+
+impl<Svc> Clone for SyncServiceRouterState<Svc> {
+ fn clone(&self) -> Self {
+ Self {
+ service: self.service.clone(),
+ }
+ }
+}
+
+pub fn sync_service_router<Svc, S>(state: SyncServiceRouterState<Svc>) -> Router<S>
+where
+ Svc: SyncWakeupService,
+ S: Send + Sync + 'static,
+{
+ Router::new()
+ .route("/wakeup", post(bulk_wakeup_handler::<Svc>))
+ .with_state(state)
+}
+
+#[utoipa::path(
+ tag = "sync_service",
+ post,
+ path = "/internal/sync_service/wakeup",
+ operation_id = "bulk_wakeup_sync_service_documents",
+ request_body = BulkWakeupRequest,
+ responses(
+ (status = 202, description = "Wakeups accepted for fire-and-forget dispatch", body = BulkWakeupResponse),
+ (status = 400, description = "Malformed request or missing internal auth header"),
+ (status = 401, description = "Invalid internal auth header"),
+ )
+)]
+pub async fn bulk_wakeup_handler<Svc>(
+ State(state): State<SyncServiceRouterState<Svc>>,
+ Json(request): Json<BulkWakeupRequest>,
+) -> Response
+where
+ Svc: SyncWakeupService,
+{
+ let dispatched = state.service.bulk_wakeup(request.document_ids);
+
+ (
+ StatusCode::ACCEPTED,
+ Json(BulkWakeupResponse { dispatched }),
+ )
+ .into_response()
+}
diff --git a/rust/cloud-storage/sync_service/src/lib.rs b/rust/cloud-storage/sync_service/src/lib.rs
new file mode 100644
index 0000000000..f305fbcdbe
--- /dev/null
+++ b/rust/cloud-storage/sync_service/src/lib.rs
@@ -0,0 +1,4 @@
+pub mod domain;
+
+#[cfg(feature = "inbound")]
+pub mod inbound;
diff --git a/rust/cloud-storage/sync_service_client/Cargo.toml b/rust/cloud-storage/sync_service_client/Cargo.toml
index 26b1fcf97d..4a0de87f15 100644
--- a/rust/cloud-storage/sync_service_client/Cargo.toml
+++ b/rust/cloud-storage/sync_service_client/Cargo.toml
@@ -9,6 +9,8 @@ anyhow = { workspace = true }
model = { path = "../model" }
reqwest = { workspace = true }
serde = { workspace = true }
+sync_service_hex = { path = "../sync_service", package = "sync_service" }
+tokio = { workspace = true }
tracing = { workspace = true }
[dev-dependencies]
diff --git a/rust/cloud-storage/sync_service_client/src/lib.rs b/rust/cloud-storage/sync_service_client/src/lib.rs
index 9fbdbe8d3e..8f2a94b6d1 100644
--- a/rust/cloud-storage/sync_service_client/src/lib.rs
+++ b/rust/cloud-storage/sync_service_client/src/lib.rs
@@ -3,6 +3,7 @@ pub mod delete;
pub mod exists;
pub mod get_raw;
pub mod metadata;
+pub mod wakeup;
pub(crate) static INTERNAL_ACCESS_HEADER: &str = "x-internal-auth-key";
diff --git a/rust/cloud-storage/sync_service_client/src/wakeup.rs b/rust/cloud-storage/sync_service_client/src/wakeup.rs
new file mode 100644
index 0000000000..8949285494
--- /dev/null
+++ b/rust/cloud-storage/sync_service_client/src/wakeup.rs
@@ -0,0 +1,35 @@
+use super::SyncServiceClient;
+use sync_service_hex::domain::ports::SyncWakeupService;
+
+impl SyncServiceClient {
+ pub fn bulk_wakeup_fire_and_forget(&self, document_ids: Vec<String>) -> usize {
+ let dispatched = document_ids.len();
+
+ for document_id in document_ids {
+ self.wakeup_fire_and_forget(document_id);
+ }
+
+ dispatched
+ }
+
+ pub fn wakeup_fire_and_forget(&self, document_id: String) {
+ let client = self.client.clone();
+ let full_url = format!("{}/document/{}/wakeup", self.url, document_id);
+
+ std::mem::drop(tokio::spawn(async move {
+ if let Err(error) = client.head(&full_url).send().await {
+ tracing::warn!(
+ error = ?error,
+ document_id = %document_id,
+ "failed to dispatch sync service wakeup",
+ );
+ }
+ }));
+ }
+}
+
+impl SyncWakeupService for SyncServiceClient {
+ fn bulk_wakeup(&self, document_ids: Vec<String>) -> usize {
+ self.bulk_wakeup_fire_and_forget(document_ids)
+ }
+}