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
feat(email-service): Retry queue for webhook pubsub processing (#390)
Evan Hutnikb655dbf68505
diff --git a/infra/stacks/email-service/Pulumi.dev.yaml b/infra/stacks/email-service/Pulumi.dev.yamlindex 070d7ee1dd..13c61008eb 100644--- a/infra/stacks/email-service/Pulumi.dev.yaml+++ b/infra/stacks/email-service/Pulumi.dev.yaml@@ -15,6 +15,8 @@ config:email-service:backfill_queue_max_messages: 1email-service:webhook_queue_workers: 25email-service:webhook_queue_max_messages: 1+ email-service:webhook_retry_queue_workers: 15+ email-service:webhook_retry_queue_max_messages: 1email-service:sfs_uploader_workers: 3email-service:presigned_url_ttl_secs: 3600email-service:gmail_gcp_queue: gmail-gcp-queue-devdiff --git a/infra/stacks/email-service/Pulumi.prod.yaml b/infra/stacks/email-service/Pulumi.prod.yamlindex e826400399..b750e1d55c 100644--- a/infra/stacks/email-service/Pulumi.prod.yaml+++ b/infra/stacks/email-service/Pulumi.prod.yaml@@ -15,6 +15,8 @@ config:email-service:backfill_queue_max_messages: 1email-service:webhook_queue_workers: 25email-service:webhook_queue_max_messages: 1+ email-service:webhook_retry_queue_workers: 15+ email-service:webhook_retry_queue_max_messages: 1email-service:sfs_uploader_workers: 3email-service:presigned_url_ttl_secs: 3600email-service:gmail_gcp_queue: gmail-gcp-queue-proddiff --git a/infra/stacks/email-service/index.ts b/infra/stacks/email-service/index.tsindex 732e967754..636fdc0e7f 100644--- a/infra/stacks/email-service/index.ts+++ b/infra/stacks/email-service/index.ts@@ -44,6 +44,12 @@ const BACKFILL_QUEUE_MAX_MESSAGES = config.require();const WEBHOOK_QUEUE_WORKERS = config.require(`webhook_queue_workers`);const WEBHOOK_QUEUE_MAX_MESSAGES = config.require(`webhook_queue_max_messages`);+const WEBHOOK_RETRY_QUEUE_WORKERS = config.require(+ `webhook_retry_queue_workers`+);+const WEBHOOK_RETRY_QUEUE_MAX_MESSAGES = config.require(+ `webhook_retry_queue_max_messages`+);const SFS_UPLOADER_WORKERS = config.require(`sfs_uploader_workers`);const gmailGcpQueue = config.require(`gmail_gcp_queue`);const GMAIL_GCP_QUEUE = aws.secretsmanager@@ -116,13 +122,22 @@ const macroDbUrlArn: pulumi.Output<string> = aws.secretsmanagerconst webhook_queue = new Queue('email-service-gmail-webhook', {tags,- maxReceiveCount: 20,+ maxReceiveCount: 5,visibilityTimeoutSeconds: 60,});export const webhookQueueArn = pulumi.interpolate`${webhook_queue.queue.arn}`;export const webhookQueueName = pulumi.interpolate`${webhook_queue.queue.name}`;+const webhook_retry_queue = new Queue('email-service-gmail-webhook-retry', {+ tags,+ maxReceiveCount: 100,+ visibilityTimeoutSeconds: 60,+});++export const webhookRetryQueueArn = pulumi.interpolate`${webhook_retry_queue.queue.arn}`;+export const webhookRetryQueueName = pulumi.interpolate`${webhook_retry_queue.queue.name}`;+const refresh_queue = new Queue('email-service-refresh', {tags,});@@ -211,6 +226,7 @@ const secretKeyArns = [const queueArns = [notificationQueueArn,webhookQueueArn,+ webhookRetryQueueArn,refreshQueueArn,scheduledQueueArn,searchEventQueueArn,@@ -261,6 +277,10 @@ const emailService = new EmailService('email-service', {name: 'GMAIL_WEBHOOK_QUEUE',value: webhookQueueName,},+ {+ name: 'GMAIL_WEBHOOK_RETRY_QUEUE',+ value: webhookRetryQueueName,+ },{name: 'BACKFILL_QUEUE',value: backfillQueueName,@@ -349,6 +369,14 @@ const emailService = new EmailService('email-service', {name: 'WEBHOOK_QUEUE_MAX_MESSAGES',value: pulumi.interpolate`${WEBHOOK_QUEUE_MAX_MESSAGES}`,},+ {+ name: 'WEBHOOK_RETRY_QUEUE_WORKERS',+ value: pulumi.interpolate`${WEBHOOK_RETRY_QUEUE_WORKERS}`,+ },+ {+ name: 'WEBHOOK_RETRY_QUEUE_MAX_MESSAGES',+ value: pulumi.interpolate`${WEBHOOK_RETRY_QUEUE_MAX_MESSAGES}`,+ },{name: 'SFS_UPLOADER_WORKERS',value: pulumi.interpolate`${SFS_UPLOADER_WORKERS}`,diff --git a/rust/cloud-storage/email_service/justfile b/rust/cloud-storage/email_service/justfileindex 6b4368dba3..119fd45424 100644--- a/rust/cloud-storage/email_service/justfile+++ b/rust/cloud-storage/email_service/justfile@@ -26,6 +26,8 @@ start-localstack:create-queues:AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue \--queue-name my-test-webhook-queue --attributes VisibilityTimeout=60+ AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue \+ --queue-name my-test-webhook-retry-queue --attributes VisibilityTimeout=60AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue \--queue-name my-test-refresh-queueAWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue \@@ -48,6 +50,8 @@ purge-queues:--queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/backfill-queueAWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs purge-queue \--queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/my-test-webhook-queue+ AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs purge-queue \+ --queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/my-test-webhook-retry-queueAWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs purge-queue \--queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/my-test-refresh-queueAWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs purge-queue \diff --git a/rust/cloud-storage/email_service/src/config.rs b/rust/cloud-storage/email_service/src/config.rsindex 9c02451353..d09cc7c5e0 100644--- a/rust/cloud-storage/email_service/src/config.rs+++ b/rust/cloud-storage/email_service/src/config.rs@@ -25,6 +25,10 @@ pub struct Config {/// The SQS queue name we process history updates from.pub gmail_webhook_queue: String,+ /// The SQS queue name we process history update retries from. Separate from the main queue+ /// to avoid backups for large inbox update operations+ pub gmail_webhook_retry_queue: String,+/// The SQS queue name for search eventpub search_event_queue: String,@@ -67,6 +71,12 @@ pub struct Config {/// The queue max messages per poll for gmail webhookpub webhook_queue_max_messages: i32,+ /// The number of workers we spawn for gmail retry webhook+ pub webhook_retry_queue_workers: i32,++ /// The queue max messages per poll for gmail retry webhook+ pub webhook_retry_queue_max_messages: i32,+/// The number of workers we spawn for sfs uploaderpub sfs_uploader_workers: i32,@@ -135,6 +145,9 @@ impl Config {let gmail_webhook_queue =std::env::var("GMAIL_WEBHOOK_QUEUE").context("GMAIL_WEBHOOK_QUEUE must be provided")?;+ let gmail_webhook_retry_queue = std::env::var("GMAIL_WEBHOOK_RETRY_QUEUE")+ .context("GMAIL_WEBHOOK_RETRY_QUEUE must be provided")?;+let search_event_queue =std::env::var("SEARCH_EVENT_QUEUE").context("SEARCH_EVENT_QUEUE must be provided")?;@@ -189,6 +202,17 @@ impl Config {.parse::<i32>().unwrap();+ let webhook_retry_queue_workers: i32 = std::env::var("WEBHOOK_RETRY_QUEUE_WORKERS")+ .unwrap_or("10".to_string())+ .parse::<i32>()+ .unwrap();++ let webhook_retry_queue_max_messages: i32 =+ std::env::var("WEBHOOK_RETRY_QUEUE_MAX_MESSAGES")+ .unwrap_or("1".to_string())+ .parse::<i32>()+ .unwrap();+let sfs_uploader_workers: i32 = std::env::var("SFS_UPLOADER_WORKERS").unwrap_or("3".to_string()).parse::<i32>()@@ -244,6 +268,7 @@ impl Config {email_refresh_queue,email_scheduled_queue,gmail_webhook_queue,+ gmail_webhook_retry_queue,search_event_queue,insight_context_queue,gmail_gcp_queue,@@ -259,6 +284,8 @@ impl Config {backfill_queue_max_messages,webhook_queue_workers,webhook_queue_max_messages,+ webhook_retry_queue_workers,+ webhook_retry_queue_max_messages,sfs_uploader_workers,redis_rate_limit_reqs,redis_rate_limit_window_secs,diff --git a/rust/cloud-storage/email_service/src/main.rs b/rust/cloud-storage/email_service/src/main.rsindex 9e49ec8877..cebb52540a 100644--- a/rust/cloud-storage/email_service/src/main.rs+++ b/rust/cloud-storage/email_service/src/main.rs@@ -56,7 +56,7 @@ async fn main() -> anyhow::Result<()> {// limiting to max of 400 connections (25% of macrodb total) in prod. (10 service + 30 backfill) * 10 pod maxlet (min_connections, max_connections): (u32, u32) = match config.environment {- Environment::Production => (3, 10),+ Environment::Production => (3, 30),Environment::Develop => (1, 10),Environment::Local => (1, 10),};@@ -97,6 +97,7 @@ async fn main() -> anyhow::Result<()> {let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(&gmail_queue_aws_config)).gmail_webhook_queue(&config.gmail_webhook_queue)+ .gmail_webhook_retry_queue(&config.gmail_webhook_retry_queue).search_event_queue(&config.search_event_queue).insight_context_queue(&config.insight_context_queue).email_backfill_queue(&config.backfill_queue)@@ -157,6 +158,17 @@ async fn main() -> anyhow::Result<()> {}).collect::<Vec<_>>();+ let webhook_retry_workers = (0..config.webhook_retry_queue_workers)+ .map(|_| {+ sqs_worker::SQSWorker::new(+ aws_sdk_sqs::Client::new(&gmail_queue_aws_config),+ config.gmail_webhook_retry_queue.clone(),+ config.webhook_retry_queue_max_messages,+ config.queue_wait_time_seconds,+ )+ })+ .collect::<Vec<_>>();+let auth_service_client = authentication_service_client::AuthServiceClient::new(auth_service_secret_key,config.auth_service_url.clone(),@@ -199,6 +211,7 @@ async fn main() -> anyhow::Result<()> {config.connection_gateway_url.clone(),);+ // process user inbox updates from gmail webhook queue, triggered by update pubsub messages from Googlefor worker in webhook_workers {let db_webhook = db.clone();let sqs_client_webhook = sqs_client.clone();@@ -222,6 +235,41 @@ async fn main() -> anyhow::Result<()> {connection_gateway_client_webhook,dss_client_webhook,config.notifications_enabled,+ false,+ )+ .await;+ });+ }+ tracing::info!(+ num_workers = config.webhook_queue_workers,+ "webhook workers started"+ );++ // separate queue for retries to avoid backups for large inbox updates that hit gmail api rate limit+ for worker in webhook_retry_workers {+ let db_webhook = db.clone();+ let sqs_client_webhook = sqs_client.clone();+ let gmail_client_webhook = gmail_client.clone();+ let auth_service_client_webhook = auth_service_client.clone();+ let redis_client_webhook = redis_client.clone();+ let macro_notify_client_webhook = macro_notify_client.clone();+ let sfs_client_webhook = sfs_client.clone();+ let connection_gateway_client_webhook = connection_gateway_client.clone();+ let dss_client_webhook = dss_client.clone();+ tokio::spawn(async move {+ pubsub::webhook::worker::run_worker(+ db_webhook,+ worker,+ sqs_client_webhook,+ gmail_client_webhook,+ auth_service_client_webhook,+ redis_client_webhook,+ macro_notify_client_webhook,+ sfs_client_webhook,+ connection_gateway_client_webhook,+ dss_client_webhook,+ config.notifications_enabled,+ true,).await;});@@ -231,6 +279,7 @@ async fn main() -> anyhow::Result<()> {"webhook workers started");+ // backfill user emails upon signupfor worker in backfill_workers {let db_backfill = db_backfill.clone();let sqs_client_backfill = sqs_client.clone();@@ -268,6 +317,7 @@ async fn main() -> anyhow::Result<()> {let auth_service_client_refresh = auth_service_client.clone();let redis_client_refresh = redis_client.clone();let sqs_client_refresh = sqs_client.clone();+ // daily refresh operations for user contacts and inbox subscriptionstokio::spawn(async move {pubsub::refresh::worker::run_worker(refresh_worker,@@ -284,6 +334,7 @@ async fn main() -> anyhow::Result<()> {let gmail_client_scheduled = gmail_client.clone();let auth_service_client_scheduled = auth_service_client.clone();let redis_client_scheduled = redis_client.clone();+ // send scheduled emailstokio::spawn(async move {pubsub::scheduled::worker::run_worker(scheduled_worker,@@ -299,6 +350,7 @@ async fn main() -> anyhow::Result<()> {for worker in sfs_uploader_workers {let db_sfs_uploader = db.clone();let sfs_client_sfs_uploader = sfs_client.clone();+ // upload user contact images to sfs from contact synctokio::spawn(async move {pubsub::sfs_uploader::worker::run_worker(worker,diff --git a/rust/cloud-storage/email_service/src/pubsub/backfill/worker.rs b/rust/cloud-storage/email_service/src/pubsub/backfill/worker.rsindex b66b7e481b..9d4f663c67 100644--- a/rust/cloud-storage/email_service/src/pubsub/backfill/worker.rs+++ b/rust/cloud-storage/email_service/src/pubsub/backfill/worker.rs@@ -35,6 +35,7 @@ pub async fn run_worker(connection_gateway_client,dss_client,notifications_enabled,+ retry_worker: false,};loop {diff --git a/rust/cloud-storage/email_service/src/pubsub/context.rs b/rust/cloud-storage/email_service/src/pubsub/context.rsindex 29f0166cab..a79d5dd13e 100644--- a/rust/cloud-storage/email_service/src/pubsub/context.rs+++ b/rust/cloud-storage/email_service/src/pubsub/context.rs@@ -20,4 +20,5 @@ pub struct PubSubContext {pub connection_gateway_client: ConnectionGatewayClient,pub dss_client: DocumentStorageServiceClient,pub notifications_enabled: bool,+ pub retry_worker: bool,}diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/gmail_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/gmail_message.rsindex 0719bba98f..9143b903ad 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/gmail_message.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/gmail_message.rs@@ -55,11 +55,14 @@ pub async fn gmail_message(return Ok(());}- // ensure user's labels are synced before we start processing changes+ // ensure user's labels are synced before we start processing changes.check_gmail_rate_limit(&ctx.redis_client,link.id,GmailApiOperation::LabelsList,+ // don't retry if rate limited, just wait until the next inbox update comes in. if we're+ // rate limited it's likely because of a large previous inbox update, so let that get+ // fully processed before the next one.false,).await?;@@ -80,6 +83,9 @@ pub async fn gmail_message(&ctx.redis_client,link.id,GmailApiOperation::HistoryList,+ // don't retry if rate limited, just wait until the next inbox update comes in. if we're+ // rate limited it's likely because of a large previous inbox update, so let that get+ // fully processed before the next one.false,).await?;diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/update_labels.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/update_labels.rsindex ea4ac00598..d794a00619 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/update_labels.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/update_labels.rs@@ -1,14 +1,13 @@use crate::pubsub::context::PubSubContext;-use crate::pubsub::util::{- cg_refresh_email, check_gmail_rate_limit, complete_transaction_with_processing_error,-};+use crate::pubsub::util::{cg_refresh_email, complete_transaction_with_processing_error};use crate::pubsub::webhook::process;+use crate::pubsub::webhook::process::check_gmail_rate_limit_webhook;use email_db_client::labels::delete::delete_db_message_labels;use email_db_client::labels::insert;use email_db_client::threads::update::update_thread_metadata;use models_email::email::service::link;use models_email::gmail::operations::GmailApiOperation;-use models_email::gmail::webhook::UpdateLabelsPayload;+use models_email::gmail::webhook::{UpdateLabelsPayload, WebhookOperation};use models_email::service;use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingError};use sqlx::PgPool;@@ -56,13 +55,15 @@ pub async fn update_labels(})})?;- check_gmail_rate_limit(- &ctx.redis_client,+ // get the message labels from gmail+ check_gmail_rate_limit_webhook(+ ctx,link.id,GmailApiOperation::MessagesGet,- false,+ WebhookOperation::UpdateLabels(payload.clone()),).await?;+let gmail_message_labels = match ctx.gmail_client.get_message_label_ids(&gmail_access_token, &payload.provider_message_id, link.id)diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rsindex 6bfe5f9b2b..6e77db8267 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/operations/upsert_message.rs@@ -1,6 +1,7 @@use crate::pubsub::context::PubSubContext;-use crate::pubsub::util::{cg_refresh_email, check_gmail_rate_limit};+use crate::pubsub::util::cg_refresh_email;use crate::pubsub::webhook::process;+use crate::pubsub::webhook::process::check_gmail_rate_limit_webhook;use crate::util::process_pre_insert::{process_message_pre_insert, process_threads_pre_insert};use crate::util::upload_attachment::upload_attachment;use email_db_client::threads;@@ -22,7 +23,7 @@ use models_email::email::service::link;use models_email::email::service::message::SimpleMessage;use models_email::email::service::thread::UserThreadIds;use models_email::gmail::operations::GmailApiOperation;-use models_email::gmail::webhook::UpsertMessagePayload;+use models_email::gmail::webhook::{UpsertMessagePayload, WebhookOperation};use models_email::service::message::Message;use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingError};use models_opensearch::SearchEntityType;@@ -43,13 +44,14 @@ pub async fn upsert_message(let gmail_access_token = process::fetch_pubsub_gmail_token(ctx, link).await?;// we have to fetch the message to get its provider thread id- check_gmail_rate_limit(- &ctx.redis_client,+ check_gmail_rate_limit_webhook(+ ctx,link.id,GmailApiOperation::MessagesGet,- false,+ WebhookOperation::UpsertMessage(payload.clone()),).await?;+let message = match ctx.gmail_client.get_message(&gmail_access_token, &payload.provider_message_id, link.id)@@ -129,14 +131,20 @@ pub async fn upsert_message(})})?;} else {- fetch_and_insert_thread(ctx, &gmail_access_token, link.id, &provider_thread_id)- .await- .map_err(|e| {- ProcessingError::Retryable(DetailedError {- reason: FailureReason::DatabaseQueryFailed,- source: e.context("Failed to fetch and insert thread".to_string()),- })- })?;+ fetch_and_insert_thread(+ ctx,+ payload,+ &gmail_access_token,+ link.id,+ &provider_thread_id,+ )+ .await+ .map_err(|e| {+ ProcessingError::Retryable(DetailedError {+ reason: FailureReason::DatabaseQueryFailed,+ source: e.context("Failed to fetch and insert thread".to_string()),+ })+ })?;}// trigger FE inbox refresh@@ -386,18 +394,21 @@ async fn generate_email_insights_for_new_messages(#[tracing::instrument(skip(ctx, gmail_access_token))]async fn fetch_and_insert_thread(ctx: &PubSubContext,+ payload: &UpsertMessagePayload,gmail_access_token: &str,link_id: Uuid,provider_thread_id: &str,) -> anyhow::Result<()> {// fetch threads- check_gmail_rate_limit(- &ctx.redis_client,+ check_gmail_rate_limit_webhook(+ ctx,link_id,GmailApiOperation::ThreadsGet,- false,+ WebhookOperation::UpsertMessage(payload.clone()),)- .await?;+ .await+ .map_err(anyhow::Error::from)?;+let mut threads = ctx.gmail_client.get_threads(diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/process.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/process.rsindex 1d7bd5cfd5..f4f465c68e 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/process.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/process.rs@@ -7,11 +7,13 @@ use crate::pubsub::webhook::operations::upsert_message::upsert_message;use anyhow::{Context, Result, anyhow};use models_email::email::service::cache;use models_email::email::service::link::UserProvider;+use models_email::gmail::operations::GmailApiOperation;use models_email::gmail::webhook::{WebhookOperation, WebhookPubsubMessage};use models_email::service::link::Link;use models_email::service::pubsub::{DetailedError, FailureReason, ProcessingError};use sqs_worker::cleanup_message;use std::result;+use uuid::Uuid;/// Processes a message from the gmail webhook queue.pub async fn process_message(@@ -148,3 +150,49 @@ pub async fn fetch_pubsub_gmail_token(})?;Ok(gmail_access_token)}++/// Checks Gmail API rate limits and routes processing accordingly.+///+/// Uses a two-tier webhook system to prevent rate limit backpressure:+/// - **Primary worker**: If rate limited, enqueues to retry queue and returns non-retryable error+/// - **Retry worker**: If rate limited, returns retryable error so it gets tried again later+///+/// This design keeps the primary queue flowing by offloading rate-limited operations to a+/// separate retry queue, preventing head-of-line blocking.+pub async fn check_gmail_rate_limit_webhook(+ ctx: &PubSubContext,+ link_id: Uuid,+ operation: GmailApiOperation,+ webhook_operation: WebhookOperation,+) -> result::Result<(), ProcessingError> {+ if !ctx.redis_client.is_rate_limited(link_id, operation).await {+ // Not rate limited, continue processing+ return Ok(());+ }++ if !ctx.retry_worker {+ ctx.sqs_client+ .enqueue_gmail_retry_webhook_notification(WebhookPubsubMessage {+ link_id,+ operation: webhook_operation,+ })+ .await+ .map_err(|e| {+ ProcessingError::NonRetryable(DetailedError {+ reason: FailureReason::SqsEnqueueFailed,+ source: e.context("Failed to enqueue retry message"),+ })+ })?;+ Err(ProcessingError::NonRetryable(DetailedError {+ reason: FailureReason::GmailApiRateLimited,+ source: anyhow::Error::msg(+ "Gmail API rate limit exceeded, enqueued message on retry queue",+ ),+ }))+ } else {+ Err(ProcessingError::Retryable(DetailedError {+ reason: FailureReason::GmailApiRateLimited,+ source: anyhow::Error::msg("Gmail API rate limit exceeded in retry worker"),+ }))+ }+}diff --git a/rust/cloud-storage/email_service/src/pubsub/webhook/worker.rs b/rust/cloud-storage/email_service/src/pubsub/webhook/worker.rsindex a21d40b7cd..92b01f4216 100644--- a/rust/cloud-storage/email_service/src/pubsub/webhook/worker.rs+++ b/rust/cloud-storage/email_service/src/pubsub/webhook/worker.rs@@ -22,6 +22,7 @@ pub async fn run_worker(connection_gateway_client: ConnectionGatewayClient,dss_client: DocumentStorageServiceClient,notifications_enabled: bool,+ retry_worker: bool,) {let ctx = PubSubContext {db,@@ -35,6 +36,7 @@ pub async fn run_worker(connection_gateway_client,dss_client,notifications_enabled,+ retry_worker,};loop {diff --git a/rust/cloud-storage/sqs_client/src/gmail.rs b/rust/cloud-storage/sqs_client/src/gmail.rsindex 66b7664464..778c0d783d 100644--- a/rust/cloud-storage/sqs_client/src/gmail.rs+++ b/rust/cloud-storage/sqs_client/src/gmail.rs@@ -7,6 +7,11 @@ impl SQS {self}+ pub fn gmail_webhook_retry_queue(mut self, gmail_webhook_retry_queue: &str) -> Self {+ self.gmail_webhook_retry_queue = Some(gmail_webhook_retry_queue.to_string());+ self+ }+/// Sends a notification message to the Gmail webhook queue#[tracing::instrument(skip(self))]pub async fn enqueue_gmail_webhook_notification(@@ -16,7 +21,20 @@ impl SQS {if let Some(gmail_webhook_queue) = &self.gmail_webhook_queue {return enqueue_webhook_notification(&self.inner, gmail_webhook_queue, message).await;}- Err(anyhow::anyhow!("gmail_webhook_queue is not configured"))+ anyhow::bail!("gmail_webhook_queue is not configured")+ }++ /// Sends a notification message to the Gmail retry webhook queue+ #[tracing::instrument(skip(self))]+ pub async fn enqueue_gmail_retry_webhook_notification(+ &self,+ message: WebhookPubsubMessage,+ ) -> anyhow::Result<()> {+ if let Some(gmail_webhook_retry_queue) = &self.gmail_webhook_retry_queue {+ return enqueue_webhook_notification(&self.inner, gmail_webhook_retry_queue, message)+ .await;+ }+ anyhow::bail!("gmail_webhook_retry_queue is not configured")}}diff --git a/rust/cloud-storage/sqs_client/src/lib.rs b/rust/cloud-storage/sqs_client/src/lib.rsindex c7b896a6fd..16d2da7e5a 100644--- a/rust/cloud-storage/sqs_client/src/lib.rs+++ b/rust/cloud-storage/sqs_client/src/lib.rs@@ -76,6 +76,8 @@ pub struct SQS {insight_context_queue: Option<String>,#[cfg(feature = "gmail")]gmail_webhook_queue: Option<String>,+ #[cfg(feature = "gmail")]+ gmail_webhook_retry_queue: Option<String>,#[cfg(feature = "email")]email_refresh_queue: Option<String>,#[cfg(feature = "email")]@@ -110,6 +112,8 @@ impl SQS {insight_context_queue: None,#[cfg(feature = "gmail")]gmail_webhook_queue: None,+ #[cfg(feature = "gmail")]+ gmail_webhook_retry_queue: None,#[cfg(feature = "email")]email_refresh_queue: None,#[cfg(feature = "email")]