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(email-service): Sfs delete lambda and handler (#1018)

Evan Hutnike41490f41621
diff --git a/.github/services-config.json b/.github/services-config.json
index da46b64b02..196140a097 100644
--- a/.github/services-config.json
+++ b/.github/services-config.json
@@ -127,6 +127,12 @@
],
"stack_path": "infra/stacks/search-upload/**"
},
+ "email-sfs-delete-handler": {
+ "source_paths": [
+ "rust/cloud-storage/email_sfs_delete_handler/**"
+ ],
+ "stack_path": "infra/stacks/email-sfs-delete-handler/**"
+ },
"static-file-service": {
"source_paths": [
"rust/cloud-storage/static_file_service/**"
diff --git a/.github/workflows/code-check-cloud-storage.yml b/.github/workflows/code-check-cloud-storage.yml
index 2601c52307..21c7c1c27e 100644
--- a/.github/workflows/code-check-cloud-storage.yml
+++ b/.github/workflows/code-check-cloud-storage.yml
@@ -104,6 +104,7 @@ jobs:
deleted_item_poller: ${{ steps.changes.outputs.deleted_item_poller }}
email_refresh_handler: ${{ steps.changes.outputs.email_refresh_handler }}
email_scheduled_handler: ${{ steps.changes.outputs.email_scheduled_handler }}
+ email_sfs_delete_handler: ${{ steps.changes.outputs.email_sfs_delete_handler }}
user_link_cleanup_handler: ${{ steps.changes.outputs.user_link_cleanup_handler }}
steps:
- uses: actions/checkout@v4
@@ -125,6 +126,7 @@ jobs:
deleted_item_poller: ./rust/cloud-storage/deleted_item_poller/*
email_refresh_handler: ./rust/cloud-storage/email_refresh_handler/*
email_scheduled_handler: ./rust/cloud-storage/email_scheduled_handler/*
+ email_sfs_delete_handler: ./rust/cloud-storage/email_sfs_delete_handler/*
user_link_cleanup_handler: ./rust/cloud-storage/user_link_cleanup_handler/*
lambda_aggregate_frecency: ./rust/cloud-storage/lambda_aggregate_frecency/*
@@ -150,6 +152,7 @@ jobs:
- service: deleted_item_poller
- service: email_refresh_handler
- service: email_scheduled_handler
+ - service: email_sfs_delete_handler
- service: user_link_cleanup_handler
steps:
- name: setup env var
diff --git a/infra/bun.lock b/infra/bun.lock
index 38ce2b88c1..f2750d0dfb 100644
--- a/infra/bun.lock
+++ b/infra/bun.lock
@@ -1,6 +1,5 @@
{
"lockfileVersion": 1,
- "configVersion": 0,
"workspaces": {
"": {
"name": "cloud-storage-infra",
@@ -107,6 +106,10 @@
"name": "email-service-stack",
"version": "0.0.0",
},
+ "stacks/email-sfs-delete-handler": {
+ "name": "email-sfs-delete-handler-stack",
+ "version": "0.0.0",
+ },
"stacks/email-suppression": {
"name": "email-suppression-stack",
"version": "0.0.0",
@@ -630,6 +633,8 @@
"email-service-stack": ["email-service-stack@workspace:stacks/email-service"],
+ "email-sfs-delete-handler-stack": ["email-sfs-delete-handler-stack@workspace:stacks/email-sfs-delete-handler"],
+
"email-suppression-stack": ["email-suppression-stack@workspace:stacks/email-suppression"],
"emoji-regex": ["[email protected]", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
diff --git a/infra/stacks/email-service/index.ts b/infra/stacks/email-service/index.ts
index e4d6015363..7e099526a0 100644
--- a/infra/stacks/email-service/index.ts
+++ b/infra/stacks/email-service/index.ts
@@ -109,6 +109,21 @@ const cloudStorageClusterName: pulumi.Output<string> = cloudStorageStack
.getOutput('cloudStorageClusterName')
.apply((arn) => arn as string);
+const sfsDeleteLambdaStack = new pulumi.StackReference(
+ 'email-sfs-delete-handler-stack',
+ {
+ name: `macro-inc/email-sfs-delete-handler/${stack}`,
+ }
+);
+
+const sfsDeleteQueueArn: pulumi.Output<string> = sfsDeleteLambdaStack
+ .getOutput('sfsDeleteQueueArn')
+ .apply((arn) => arn as string);
+
+const sfsDeleteQueueName: pulumi.Output<string> = sfsDeleteLambdaStack
+ .getOutput('sfsDeleteQueueName')
+ .apply((name) => name as string);
+
const { notificationQueueName, notificationQueueArn } = getMacroNotify();
const emailServiceRedis = new Redis('email-service-redis', {
@@ -187,6 +202,8 @@ const sfs_uploader_queue = new Queue('email-service-sfs-mapper', {
export const sfsUploaderQueueArn = pulumi.interpolate`${sfs_uploader_queue.queue.arn}`;
export const sfsUploaderQueueName = pulumi.interpolate`${sfs_uploader_queue.queue.name}`;
+export { sfsDeleteQueueArn, sfsDeleteQueueName };
+
const { searchEventQueueName, searchEventQueueArn } = getSearchEventQueue();
// Retrieve name of queue used Contacts Service
@@ -236,6 +253,7 @@ const queueArns = [
searchEventQueueArn,
backfillQueueArn,
sfsUploaderQueueArn,
+ sfsDeleteQueueArn,
contactsQueueArn,
];
@@ -364,6 +382,10 @@ const containerEnvVars = [
name: 'SFS_UPLOADER_QUEUE',
value: sfsUploaderQueueName,
},
+ {
+ name: 'SFS_DELETE_QUEUE',
+ value: sfsDeleteQueueName,
+ },
{
name: 'GMAIL_GCP_QUEUE',
value: pulumi.interpolate`${GMAIL_GCP_QUEUE}`,
diff --git a/infra/stacks/email-sfs-delete-handler/Pulumi.dev.yaml b/infra/stacks/email-sfs-delete-handler/Pulumi.dev.yaml
new file mode 100644
index 0000000000..42644f4ac2
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/Pulumi.dev.yaml
@@ -0,0 +1,4 @@
+config:
+ aws-native:region: us-east-1
+ aws:region: us-east-1
+ email-sfs-delete-handler:macro_db_secret_key: macro-db-dev
diff --git a/infra/stacks/email-sfs-delete-handler/Pulumi.prod.yaml b/infra/stacks/email-sfs-delete-handler/Pulumi.prod.yaml
new file mode 100644
index 0000000000..bd490fb556
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/Pulumi.prod.yaml
@@ -0,0 +1,4 @@
+config:
+ aws-native:region: us-east-1
+ aws:region: us-east-1
+ email-sfs-delete-handler:macro_db_secret_key: macro-db-prod
diff --git a/infra/stacks/email-sfs-delete-handler/Pulumi.yaml b/infra/stacks/email-sfs-delete-handler/Pulumi.yaml
new file mode 100644
index 0000000000..6b67b36258
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/Pulumi.yaml
@@ -0,0 +1,3 @@
+name: email-sfs-delete-handler
+runtime: nodejs
+description: Email SFS Delete Lambda
diff --git a/infra/stacks/email-sfs-delete-handler/index.ts b/infra/stacks/email-sfs-delete-handler/index.ts
new file mode 100644
index 0000000000..c8e28e641c
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/index.ts
@@ -0,0 +1,50 @@
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { Queue } from '../../packages/resources';
+import { config, stack } from '../../packages/shared';
+import { get_coparse_api_vpc } from '../../packages/vpc';
+import { EmailSfsDeleteHandler } from './sfs_delete_lambda';
+
+const tags = {
+ environment: stack,
+ tech_lead: 'evan',
+ project: 'email-service',
+};
+
+export const coparse_api_vpc = get_coparse_api_vpc();
+
+const MACRO_DB_URL_SECRET_NAME = config.require(`macro_db_secret_key`);
+const MACRO_DB_URL = aws.secretsmanager
+ .getSecretVersionOutput({
+ secretId: MACRO_DB_URL_SECRET_NAME,
+ })
+ .apply((secret) => secret.secretString);
+
+const sfs_delete_queue = new Queue('email-sfs-delete', {
+ tags,
+ maxReceiveCount: 5,
+ visibilityTimeoutSeconds: 60,
+});
+
+export const sfsDeleteQueueArn = pulumi.interpolate`${sfs_delete_queue.queue.arn}`;
+export const sfsDeleteQueueName = pulumi.interpolate`${sfs_delete_queue.queue.name}`;
+
+const emailSfsDeleteHandler = new EmailSfsDeleteHandler(
+ 'email-sfs-delete-handler',
+ {
+ queueArns: [sfsDeleteQueueArn],
+ vpc: coparse_api_vpc,
+ envVars: {
+ DATABASE_URL: pulumi.interpolate`${MACRO_DB_URL}`,
+ ENVIRONMENT: stack,
+ RUST_LOG: 'email_sfs_delete_handler=info',
+ SFS_DELETE_QUEUE: pulumi.interpolate`${sfsDeleteQueueName}`,
+ },
+ tags,
+ }
+);
+
+export const emailSfsDeleteHandlerRoleArn = emailSfsDeleteHandler.role.arn;
+export const emailSfsDeleteHandlerLambdaName =
+ emailSfsDeleteHandler.lambda.name;
+export const emailSfsDeleteHandlerLambdaArn = emailSfsDeleteHandler.lambda.arn;
diff --git a/infra/stacks/email-sfs-delete-handler/package.json b/infra/stacks/email-sfs-delete-handler/package.json
new file mode 100644
index 0000000000..479a315509
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "email-sfs-delete-handler-stack",
+ "version": "0.0.0",
+ "private": true,
+ "license": "MIT",
+ "main": "index.ts"
+}
diff --git a/infra/stacks/email-sfs-delete-handler/sfs_delete_lambda.ts b/infra/stacks/email-sfs-delete-handler/sfs_delete_lambda.ts
new file mode 100644
index 0000000000..0e59c684b0
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/sfs_delete_lambda.ts
@@ -0,0 +1,167 @@
+import * as aws from '@pulumi/aws';
+import * as pulumi from '@pulumi/pulumi';
+import { Lambda } from '../../packages/lambda';
+import { CLOUD_TRAIL_SNS_TOPIC_ARN, stack } from '../../packages/shared';
+
+const EMAIL_LAMBDA_BASE_NAME = 'email_sfs_delete_handler';
+const CLOUD_STORAGE_BASE = `../../../rust/cloud-storage`;
+const ZIP_LOCATION = `${CLOUD_STORAGE_BASE}/target/lambda/${EMAIL_LAMBDA_BASE_NAME}/bootstrap.zip`;
+
+export type EnvVars = {
+ DATABASE_URL: pulumi.Output<string> | string;
+ SFS_DELETE_QUEUE: pulumi.Output<string> | string;
+ ENVIRONMENT: pulumi.Output<string> | string;
+ RUST_LOG: pulumi.Output<string> | string;
+};
+
+type Args = {
+ envVars: EnvVars;
+ queueArns: pulumi.Output<string>[] | string[];
+ vpc: {
+ vpcId: pulumi.Output<string> | string;
+ publicSubnetIds: pulumi.Output<string[]> | string[];
+ privateSubnetIds: pulumi.Output<string[]> | string[];
+ };
+ tags: { [key: string]: string };
+};
+
+export class EmailSfsDeleteHandler extends pulumi.ComponentResource {
+ rule: aws.cloudwatch.EventRule;
+ role: aws.iam.Role;
+ lambda: aws.lambda.Function;
+ tags: { [key: string]: string };
+ constructor(
+ name: string,
+ args: Args,
+ opts?: pulumi.ComponentResourceOptions
+ ) {
+ super('my:components:Lambda', name, {}, opts);
+ const { queueArns, vpc, envVars, tags } = args;
+
+ this.tags = tags;
+
+ const sqsPolicy = new aws.iam.Policy(
+ `${EMAIL_LAMBDA_BASE_NAME}-sqs-policy`,
+ {
+ policy: pulumi.output({
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Effect: 'Allow',
+ Action: ['sqs:SendMessage'],
+ Resource: queueArns,
+ },
+ ],
+ }),
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ this.role = new aws.iam.Role(
+ `${EMAIL_LAMBDA_BASE_NAME}-role`,
+ {
+ name: `${EMAIL_LAMBDA_BASE_NAME}-role-${stack}`,
+ assumeRolePolicy: JSON.stringify({
+ Version: '2012-10-17',
+ Statement: [
+ {
+ Action: 'sts:AssumeRole',
+ Effect: 'Allow',
+ Principal: {
+ Service: 'lambda.amazonaws.com',
+ },
+ },
+ ],
+ }),
+ managedPolicyArns: [
+ aws.iam.ManagedPolicy.AWSLambdaBasicExecutionRole,
+ aws.iam.ManagedPolicy.AWSLambdaRole,
+ aws.iam.ManagedPolicy.AWSLambdaVPCAccessExecutionRole,
+ aws.iam.ManagedPolicy.CloudWatchLogsFullAccess,
+ sqsPolicy.arn,
+ ],
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ const lambda = new Lambda<EnvVars>(
+ `${EMAIL_LAMBDA_BASE_NAME}-lambda`,
+ {
+ baseName: EMAIL_LAMBDA_BASE_NAME,
+ handlerBase: CLOUD_STORAGE_BASE,
+ zipLocation: ZIP_LOCATION,
+ vpc,
+ envVars,
+ role: this.role,
+ // The > memory size = greater speedz
+ memorySize: 256,
+ timeout: 120,
+ reservedConcurrentExecutions: 1,
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ this.lambda = lambda.lambda;
+
+ this.rule = new aws.cloudwatch.EventRule(
+ `${EMAIL_LAMBDA_BASE_NAME}-rule`,
+ {
+ name: `${EMAIL_LAMBDA_BASE_NAME}-rule-${stack}`,
+ // run at 7am UTC every day, when people be sleepin
+ scheduleExpression:
+ stack === 'prod' ? 'cron(0 8 * * ? *)' : 'rate(5 minutes)',
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+
+ new aws.cloudwatch.EventTarget(
+ `${EMAIL_LAMBDA_BASE_NAME}-daily-target`,
+ {
+ rule: this.rule.name,
+ arn: this.lambda.arn,
+ },
+ { parent: this }
+ );
+
+ new aws.lambda.Permission(
+ `${EMAIL_LAMBDA_BASE_NAME}-daily-target`,
+ {
+ action: 'lambda:InvokeFunction',
+ function: this.lambda.name,
+ principal: 'events.amazonaws.com',
+ sourceArn: this.rule.arn,
+ },
+ { parent: this }
+ );
+
+ this.setupLambdaAlarms();
+ }
+
+ setupLambdaAlarms() {
+ new aws.cloudwatch.MetricAlarm(
+ `${EMAIL_LAMBDA_BASE_NAME}-error-alarm`,
+ {
+ name: `${EMAIL_LAMBDA_BASE_NAME}-error-count-${stack}`,
+ metricName: 'Errors',
+ namespace: 'AWS/Lambda',
+ statistic: 'Sum',
+ period: 300,
+ evaluationPeriods: 1,
+ threshold: 1,
+ comparisonOperator: 'GreaterThanOrEqualToThreshold',
+ dimensions: {
+ FunctionName: this.lambda.name,
+ },
+ alarmDescription: `Alarm when ${EMAIL_LAMBDA_BASE_NAME} lambda experiences errors.`,
+ actionsEnabled: true,
+ alarmActions: [CLOUD_TRAIL_SNS_TOPIC_ARN],
+ tags: this.tags,
+ },
+ { parent: this }
+ );
+ }
+}
diff --git a/infra/stacks/email-sfs-delete-handler/tsconfig.json b/infra/stacks/email-sfs-delete-handler/tsconfig.json
new file mode 100644
index 0000000000..1864d58c15
--- /dev/null
+++ b/infra/stacks/email-sfs-delete-handler/tsconfig.json
@@ -0,0 +1,3 @@
+{
+ "extends": "../../tsconfig.json"
+}
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index 05ea93bb62..c6fe2d204e 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -3254,6 +3254,23 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "email_sfs_delete_handler"
+version = "0.1.0"
+dependencies = [
+ "anyhow",
+ "aws-config",
+ "aws-sdk-sqs",
+ "aws_lambda_events",
+ "lambda_runtime",
+ "macro_entrypoint",
+ "macro_env",
+ "sqlx",
+ "sqs_client",
+ "tokio",
+ "tracing",
+]
+
[[package]]
name = "email_suppression_handler"
version = "0.1.0"
diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.toml
index 90100cbaaf..9db82a2942 100644
--- a/rust/cloud-storage/Cargo.toml
+++ b/rust/cloud-storage/Cargo.toml
@@ -32,6 +32,7 @@ members = [
"email_db_client",
"email_refresh_handler",
"email_scheduled_handler",
+ "email_sfs_delete_handler",
"email_service",
"email_service_client",
"email_suppression_handler",
diff --git a/rust/cloud-storage/email_db_client/.sqlx/query-cf47cbebc8adc6834b44c503c18fb66ce5dbb225c7ca91b3d71dcfe398c8f95a.json b/rust/cloud-storage/email_db_client/.sqlx/query-cf47cbebc8adc6834b44c503c18fb66ce5dbb225c7ca91b3d71dcfe398c8f95a.json
new file mode 100644
index 0000000000..94ce722428
--- /dev/null
+++ b/rust/cloud-storage/email_db_client/.sqlx/query-cf47cbebc8adc6834b44c503c18fb66ce5dbb225c7ca91b3d71dcfe398c8f95a.json
@@ -0,0 +1,14 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n DELETE FROM email_attachments_sfs\n WHERE id = $1\n ",
+ "describe": {
+ "columns": [],
+ "parameters": {
+ "Left": [
+ "Uuid"
+ ]
+ },
+ "nullable": []
+ },
+ "hash": "cf47cbebc8adc6834b44c503c18fb66ce5dbb225c7ca91b3d71dcfe398c8f95a"
+}
diff --git a/rust/cloud-storage/email_db_client/src/attachments/sfs/mod.rs b/rust/cloud-storage/email_db_client/src/attachments/sfs/mod.rs
index 0a15834ddf..67fb4b5e6b 100644
--- a/rust/cloud-storage/email_db_client/src/attachments/sfs/mod.rs
+++ b/rust/cloud-storage/email_db_client/src/attachments/sfs/mod.rs
@@ -1,9 +1,8 @@
-use anyhow::Context;
use models_email::{db, service};
use sqlx::{Executor, Postgres};
/// Inserts an attachment SFS record into the database
-#[tracing::instrument(skip(executor))]
+#[tracing::instrument(skip(executor), err)]
pub async fn insert_attachment_sfs<'e, E>(
executor: E,
attachment_sfs: &service::attachment::AttachmentSfs,
@@ -23,13 +22,26 @@ where
db_attachment_sfs.sfs_id,
)
.execute(executor)
- .await
- .with_context(|| {
- format!(
- "Failed to insert attachment SFS record with id {}",
- attachment_sfs.id
- )
- })?;
+ .await?;
+
+ Ok(())
+}
+
+/// Deletes an attachment SFS record from the database by its ID
+#[tracing::instrument(skip(executor), err)]
+pub async fn delete_attachment_sfs<'e, E>(executor: E, id: sqlx::types::Uuid) -> anyhow::Result<()>
+where
+ E: Executor<'e, Database = Postgres>,
+{
+ sqlx::query!(
+ r#"
+ DELETE FROM email_attachments_sfs
+ WHERE id = $1
+ "#,
+ id,
+ )
+ .execute(executor)
+ .await?;
Ok(())
}
diff --git a/rust/cloud-storage/email_scheduled_handler/justfile b/rust/cloud-storage/email_scheduled_handler/justfile
index 56b9239380..135ba5c192 100644
--- a/rust/cloud-storage/email_scheduled_handler/justfile
+++ b/rust/cloud-storage/email_scheduled_handler/justfile
@@ -10,7 +10,7 @@ check:
SQLX_OFFLINE=true cargo check
create-queues:
- AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name my-test-scheduled-queue.fifo
+ AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name sfs-delete-queue.fifo
prepare_db:
DATABASE_URL=postgres://user:password@localhost:5432/macrodb cargo sqlx prepare
\ No newline at end of file
diff --git a/rust/cloud-storage/email_service/Cargo.toml b/rust/cloud-storage/email_service/Cargo.toml
index 1c6940c94c..9130e8c827 100644
--- a/rust/cloud-storage/email_service/Cargo.toml
+++ b/rust/cloud-storage/email_service/Cargo.toml
@@ -43,10 +43,12 @@ default = [
"contacts_sync",
"gmail_webhook_auth",
"sfs_map",
+ "sfs_delete",
]
gmail_webhook_auth = []
local_queue = []
sfs_map = []
+sfs_delete = []
[dependencies]
anyhow = { workspace = true }
@@ -114,6 +116,7 @@ sqs_client = { path = "../sqs_client", default-features = false, features = [
"email",
"gmail",
"search",
+ "sfs_delete",
"sfs_uploader"
] }
sqs_worker = { path = "../sqs_worker" }
diff --git a/rust/cloud-storage/email_service/justfile b/rust/cloud-storage/email_service/justfile
index 5364a12f28..1a65509fa1 100644
--- a/rust/cloud-storage/email_service/justfile
+++ b/rust/cloud-storage/email_service/justfile
@@ -41,6 +41,8 @@ create-queues:
--queue-name sfs-uploader-queue --attributes VisibilityTimeout=60
AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue \
--queue-name contacts-queue
+ AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue \
+ --queue-name sfs-delete-queue
purge-queues:
AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs purge-queue \
@@ -59,6 +61,8 @@ purge-queues:
--queue-url http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/sfs-uploader-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/contacts-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/sfs-delete-queue
create-bucket:
AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 s3 mb \
diff --git a/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs b/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs
index 0e09d22135..c2a4531d00 100644
--- a/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs
+++ b/rust/cloud-storage/email_service/src/bin/pubsub_workers/pubsub_workers.rs
@@ -93,6 +93,7 @@ async fn main() -> anyhow::Result<()> {
.email_backfill_queue(&config.backfill_queue)
.email_scheduled_queue(&config.email_scheduled_queue)
.sfs_uploader_queue(&config.sfs_uploader_queue)
+ .sfs_delete_queue(&config.sfs_delete_queue)
.contacts_queue(&config.contacts_queue)
.email_link_manager_queue(&config.link_manager_queue);
@@ -127,6 +128,13 @@ async fn main() -> anyhow::Result<()> {
})
.collect::<Vec<_>>();
+ let sfs_delete_worker = sqs_worker::SQSWorker::new(
+ aws_sdk_sqs::Client::new(&gmail_queue_aws_config),
+ config.sfs_delete_queue.clone(),
+ config.queue_max_messages,
+ config.queue_wait_time_seconds,
+ );
+
let backfill_workers = (0..config.backfill_queue_workers)
.map(|_| {
sqs_worker::SQSWorker::new(
@@ -276,7 +284,7 @@ async fn main() -> anyhow::Result<()> {
}
tracing::info!(
num_workers = config.inbox_sync_queue_workers,
- "inbox_sync workers started"
+ "inbox_sync retry workers started"
);
// backfill user emails upon signup
@@ -372,6 +380,21 @@ async fn main() -> anyhow::Result<()> {
);
}
+ if cfg!(feature = "sfs_delete") {
+ let db_sfs_delete = db.clone();
+ let sfs_client_sfs_delete = sfs_client.clone();
+ // delete orphaned sfs attachments
+ tokio::spawn(async move {
+ email_service::pubsub::sfs_deleter::worker::run_worker(
+ sfs_delete_worker,
+ db_sfs_delete,
+ sfs_client_sfs_delete,
+ )
+ .await;
+ });
+ tracing::info!("sfs delete worker started");
+ }
+
tracing::info!("All workers started successfully");
// Wait for shutdown signal (SIGTERM from ECS or SIGINT from Ctrl+C)
diff --git a/rust/cloud-storage/email_service/src/config.rs b/rust/cloud-storage/email_service/src/config.rs
index 64ed32cf27..5da443db63 100644
--- a/rust/cloud-storage/email_service/src/config.rs
+++ b/rust/cloud-storage/email_service/src/config.rs
@@ -44,6 +44,9 @@ pub struct Config {
/// The SQS queue name for the sfs_uploader process
pub sfs_uploader_queue: String,
+ /// The SQS queue name for the sfs_delete process
+ pub sfs_delete_queue: String,
+
/// The SQS queue name for contacts service
pub contacts_queue: String,
@@ -167,6 +170,9 @@ impl Config {
let sfs_uploader_queue =
std::env::var("SFS_UPLOADER_QUEUE").context("SFS_UPLOADER_QUEUE must be provided")?;
+ let sfs_delete_queue =
+ std::env::var("SFS_DELETE_QUEUE").context("SFS_DELETE_QUEUE must be provided")?;
+
let attachment_bucket =
std::env::var("ATTACHMENT_BUCKET").context("ATTACHMENT_BUCKET must be provided")?;
@@ -277,6 +283,7 @@ impl Config {
notification_queue,
backfill_queue,
sfs_uploader_queue,
+ sfs_delete_queue,
contacts_queue,
attachment_bucket,
notifications_enabled,
diff --git a/rust/cloud-storage/email_service/src/pubsub/mod.rs b/rust/cloud-storage/email_service/src/pubsub/mod.rs
index 16fdc901e9..94b21ae452 100644
--- a/rust/cloud-storage/email_service/src/pubsub/mod.rs
+++ b/rust/cloud-storage/email_service/src/pubsub/mod.rs
@@ -3,5 +3,7 @@ pub(crate) mod context;
pub mod inbox_sync;
pub mod link_manager;
pub mod scheduled;
+#[cfg(feature = "sfs_delete")]
+pub mod sfs_deleter;
pub mod sfs_uploader;
pub(crate) mod util;
diff --git a/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/context.rs b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/context.rs
new file mode 100644
index 0000000000..32a8a36ad1
--- /dev/null
+++ b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/context.rs
@@ -0,0 +1,9 @@
+use sqlx::PgPool;
+use static_file_service_client::StaticFileServiceClient;
+
+#[derive(Clone)]
+pub struct SFSDeleteContext {
+ pub db: PgPool,
+ pub sfs_client: StaticFileServiceClient,
+ pub sqs_worker: sqs_worker::SQSWorker,
+}
diff --git a/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/mod.rs b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/mod.rs
new file mode 100644
index 0000000000..4ea0718869
--- /dev/null
+++ b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/mod.rs
@@ -0,0 +1,3 @@
+pub(crate) mod context;
+pub(crate) mod process;
+pub mod worker;
diff --git a/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/process.rs b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/process.rs
new file mode 100644
index 0000000000..d4aae29596
--- /dev/null
+++ b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/process.rs
@@ -0,0 +1,49 @@
+use crate::pubsub::sfs_deleter::context::SFSDeleteContext;
+use anyhow::Context;
+use aws_sdk_sqs::types::Message;
+use reqwest::StatusCode;
+use sqs_client::email::SFSDeleteMessage;
+use sqs_worker::cleanup_message;
+
+/// Delete attachment from SFS
+#[tracing::instrument(skip_all, err)]
+pub async fn process_message(ctx: SFSDeleteContext, message: &Message) -> anyhow::Result<()> {
+ let sfs_message = extract_sfs_delete_notification(message)?;
+ tracing::debug!(sfs_message=?sfs_message, "Processing sfs delete message");
+
+ match ctx
+ .sfs_client
+ .delete_file(sfs_message.sfs_id.to_string().as_str())
+ .await
+ {
+ Ok(_) => {}
+ Err(e) => {
+ // Treat 404 as success - file is already gone
+ if e.downcast_ref::<reqwest::Error>()
+ .is_some_and(|re| re.status() == Some(StatusCode::NOT_FOUND))
+ {
+ tracing::info!(sfs_id = %sfs_message.sfs_id, "File already deleted from SFS");
+ } else {
+ return Err(e);
+ }
+ }
+ }
+
+ email_db_client::attachments::sfs::delete_attachment_sfs(&ctx.db, sfs_message.db_id).await?;
+ tracing::debug!(sfs_message=?sfs_message, "Successfully deleted attachment from sfs");
+
+ cleanup_message(&ctx.sqs_worker, message).await?;
+
+ Ok(())
+}
+
+/// Deserializes the SQS message body into a SFSDeleteMessage struct.
+#[tracing::instrument(skip(message), err)]
+fn extract_sfs_delete_notification(
+ message: &aws_sdk_sqs::types::Message,
+) -> anyhow::Result<SFSDeleteMessage> {
+ let message_body = message.body().context("message body not found")?;
+
+ serde_json::from_str(message_body)
+ .context("Failed to deserialize message body to SFSDeleteMessage")
+}
diff --git a/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/worker.rs b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/worker.rs
new file mode 100644
index 0000000000..bfaaee1390
--- /dev/null
+++ b/rust/cloud-storage/email_service/src/pubsub/sfs_deleter/worker.rs
@@ -0,0 +1,88 @@
+use crate::pubsub::sfs_deleter::context::SFSDeleteContext;
+use crate::pubsub::sfs_deleter::process;
+use futures::StreamExt;
+use sqlx::PgPool;
+use static_file_service_client::StaticFileServiceClient;
+
+/// method that ingests sqs messages and calls the process function for each
+pub async fn run_worker(
+ worker: sqs_worker::SQSWorker,
+ db: PgPool,
+ sfs_client: StaticFileServiceClient,
+) {
+ let ctx = SFSDeleteContext {
+ db,
+ sfs_client,
+ sqs_worker: worker.clone(),
+ };
+ loop {
+ let worker_result = tokio::spawn({
+ let ctx = ctx.clone();
+ let worker = worker.clone();
+ async move {
+ loop {
+ match worker.receive_messages().await {
+ Ok(messages) => {
+ if messages.is_empty() {
+ continue;
+ }
+ let result = futures::stream::iter(messages.iter())
+ .then(|message| {
+ let ctx = ctx.clone();
+ async move {
+ let result = process::process_message(
+ ctx,
+ message,
+ )
+ .await;
+
+ match result {
+ Ok(_) => Ok(()),
+ Err(e) => Err((
+ message
+ .message_id
+ .clone()
+ .unwrap_or("".to_string()),
+ e,
+ )),
+ }
+ }
+ })
+ .collect::<Vec<Result<(), (String, anyhow::Error)>>>()
+ .await;
+
+ let errors = result
+ .into_iter()
+ .filter_map(|result| result.err())
+ .collect::<Vec<(String, anyhow::Error)>>();
+
+ if !errors.is_empty() {
+ for (message_id, error) in errors {
+ tracing::error!(message_id, error=?error, "error processing message");
+ }
+ }
+ }
+ Err(e) => {
+ tracing::error!(error=?e, "error receiving messages");
+ }
+ }
+ }
+ }
+ })
+ .await;
+
+ match worker_result {
+ Ok(_) => {
+ // This should never be hit
+ tracing::error!("worker exited successfully?");
+ }
+ Err(e) => {
+ tracing::error!(error=?e, "worker crashed with error");
+ }
+ }
+
+ // Add a delay before restarting to avoid rapid restart loops
+ tracing::info!("WORKER RESTARTING...");
+ tokio::time::sleep(std::time::Duration::from_secs(5)).await;
+ }
+}
diff --git a/rust/cloud-storage/email_sfs_delete_handler/.sqlx/query-edbec9f2fb09a6f4d6c51f137639b7ce0b5c5fdf66aba0a6efc62530ec611766.json b/rust/cloud-storage/email_sfs_delete_handler/.sqlx/query-edbec9f2fb09a6f4d6c51f137639b7ce0b5c5fdf66aba0a6efc62530ec611766.json
new file mode 100644
index 0000000000..20ff5c1ef8
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/.sqlx/query-edbec9f2fb09a6f4d6c51f137639b7ce0b5c5fdf66aba0a6efc62530ec611766.json
@@ -0,0 +1,26 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT\n id as \"db_id\", sfs_id\n FROM email_attachments_sfs\n WHERE\n attachment_id IS NULL\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "db_id",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "sfs_id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": []
+ },
+ "nullable": [
+ false,
+ false
+ ]
+ },
+ "hash": "edbec9f2fb09a6f4d6c51f137639b7ce0b5c5fdf66aba0a6efc62530ec611766"
+}
diff --git a/rust/cloud-storage/email_sfs_delete_handler/Cargo.toml b/rust/cloud-storage/email_sfs_delete_handler/Cargo.toml
new file mode 100644
index 0000000000..256bb92e87
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/Cargo.toml
@@ -0,0 +1,21 @@
+[package]
+edition = "2024"
+name = "email_sfs_delete_handler"
+publish = false
+version = "0.1.0"
+
+[dependencies]
+anyhow = { workspace = true }
+aws-config = { workspace = true }
+aws-sdk-sqs = { workspace = true }
+aws_lambda_events = { workspace = true, features = ["eventbridge"] }
+lambda_runtime = { workspace = true }
+macro_entrypoint = { path = "../macro_entrypoint" }
+macro_env = { path = "../macro_env" }
+sqlx = { workspace = true }
+sqs_client = { path = "../sqs_client", default-features = false, features = ["sfs_delete"] }
+tokio = { workspace = true }
+tracing = { workspace = true }
+
+[package.metadata.cargo-machete]
+ignored = ["openssl"]
diff --git a/rust/cloud-storage/email_sfs_delete_handler/README.md b/rust/cloud-storage/email_sfs_delete_handler/README.md
new file mode 100644
index 0000000000..82b89e5c1c
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/README.md
@@ -0,0 +1,7 @@
+
+# Email SFS Delete Handler
+
+This Lambda function executes daily to clean up orphaned static file service (SFS) attachments. It queries the
+`email_attachments_sfs` table for records where `attachment_id` is NULL (indicating the attachment is no longer
+linked to any email) and publishes delete messages to the SFS delete queue. This triggers the SFS delete worker
+to remove the orphaned files from the static file service and clean up the corresponding database records.
\ No newline at end of file
diff --git a/rust/cloud-storage/email_sfs_delete_handler/justfile b/rust/cloud-storage/email_sfs_delete_handler/justfile
new file mode 100644
index 0000000000..56b9239380
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/justfile
@@ -0,0 +1,16 @@
+lambda_name := file_name(justfile_directory())
+
+test:
+ cargo test --all-features
+
+build:
+ SQLX_OFFLINE=true cargo lambda build --release --bin {{lambda_name}} --output-format zip
+
+check:
+ SQLX_OFFLINE=true cargo check
+
+create-queues:
+ AWS_REGION=us-east-1 aws --endpoint-url=http://localhost:4566 sqs create-queue --queue-name my-test-scheduled-queue.fifo
+
+prepare_db:
+ DATABASE_URL=postgres://user:password@localhost:5432/macrodb cargo sqlx prepare
\ No newline at end of file
diff --git a/rust/cloud-storage/email_sfs_delete_handler/src/config.rs b/rust/cloud-storage/email_sfs_delete_handler/src/config.rs
new file mode 100644
index 0000000000..54976a7747
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/src/config.rs
@@ -0,0 +1,33 @@
+use anyhow::Context;
+pub use macro_env::Environment;
+
+#[derive(Debug, Clone)]
+pub struct Config {
+ /// The connection URL for the Postgres database this application should use.
+ pub database_url: String,
+
+ /// The queue we put messages on for deletion
+ pub email_sfs_delete_queue: String,
+
+ /// The environment we are in
+ #[allow(dead_code)]
+ pub environment: Environment,
+}
+
+impl Config {
+ pub fn from_env() -> anyhow::Result<Self> {
+ let database_url =
+ std::env::var("DATABASE_URL").context("DATABASE_URL must be provided")?;
+
+ let email_sfs_delete_queue =
+ std::env::var("SFS_DELETE_QUEUE").context("SFS_DELETE_QUEUE must be provided")?;
+
+ let environment = Environment::new_or_prod();
+
+ Ok(Config {
+ database_url,
+ email_sfs_delete_queue,
+ environment,
+ })
+ }
+}
diff --git a/rust/cloud-storage/email_sfs_delete_handler/src/context.rs b/rust/cloud-storage/email_sfs_delete_handler/src/context.rs
new file mode 100644
index 0000000000..7b9c0db64e
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/src/context.rs
@@ -0,0 +1,7 @@
+use std::sync::Arc;
+
+#[derive(Clone)]
+pub struct Context {
+ pub db: sqlx::Pool<sqlx::Postgres>,
+ pub sqs_client: Arc<sqs_client::SQS>,
+}
diff --git a/rust/cloud-storage/email_sfs_delete_handler/src/handler.rs b/rust/cloud-storage/email_sfs_delete_handler/src/handler.rs
new file mode 100644
index 0000000000..9800a759e5
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/src/handler.rs
@@ -0,0 +1,52 @@
+use crate::context::{self};
+use aws_lambda_events::eventbridge::EventBridgeEvent;
+use lambda_runtime::{
+ Error, LambdaEvent,
+ tracing::{self},
+};
+use sqs_client::email::SFSDeleteMessage;
+
+#[tracing::instrument(skip_all, err)]
+pub async fn handler(
+ ctx: context::Context,
+ _event: LambdaEvent<EventBridgeEvent>,
+) -> Result<(), Error> {
+ // grab all orphaned sfs attachments (no longer attached to any email attachment)
+ let messages = sqlx::query_as!(
+ SFSDeleteMessage,
+ r#"
+ SELECT
+ id as "db_id", sfs_id
+ FROM email_attachments_sfs
+ WHERE
+ attachment_id IS NULL
+ "#,
+ )
+ .fetch_all(&ctx.db)
+ .await
+ .unwrap_or_else(|e| {
+ tracing::error!(error=?e, "Error fetching orphaned sfs attachments");
+ Vec::new()
+ });
+
+ if !messages.is_empty() {
+ tracing::info!(count = messages.len(), "Sending sfs delete messages");
+ } else {
+ tracing::info!("No orphaned sfs attachments found");
+ }
+
+ for message in messages.into_iter() {
+ let db_id = message.db_id;
+ let sfs_id = message.sfs_id;
+ if let Err(e) = ctx.sqs_client.enqueue_sfs_delete_message(message).await {
+ tracing::error!(
+ error = ?e,
+ db_id = %db_id,
+ sfs_id = %sfs_id,
+ "Error enqueueing sfs delete message",
+ );
+ };
+ }
+
+ Ok(())
+}
diff --git a/rust/cloud-storage/email_sfs_delete_handler/src/main.rs b/rust/cloud-storage/email_sfs_delete_handler/src/main.rs
new file mode 100644
index 0000000000..0f51fdef48
--- /dev/null
+++ b/rust/cloud-storage/email_sfs_delete_handler/src/main.rs
@@ -0,0 +1,48 @@
+mod config;
+mod context;
+mod handler;
+
+use anyhow::Context;
+use aws_lambda_events::event::eventbridge::EventBridgeEvent;
+use config::Config;
+use handler::handler;
+use lambda_runtime::{Error, LambdaEvent, run, service_fn};
+use macro_entrypoint::MacroEntrypoint;
+use sqlx::postgres::PgPoolOptions;
+use std::sync::Arc;
+
+#[tokio::main]
+async fn main() -> Result<(), Error> {
+ MacroEntrypoint::default().init();
+
+ let config = Config::from_env().context("all necessary env vars should be available")?;
+
+ // should only need a single connection to fetch the list of emails
+ let db = PgPoolOptions::new()
+ .min_connections(1)
+ .max_connections(1)
+ .connect(&config.database_url)
+ .await
+ .context("could not connect to db")?;
+
+ let sqs_client = sqs_client::SQS::new(aws_sdk_sqs::Client::new(
+ &aws_config::defaults(aws_config::BehaviorVersion::latest())
+ .region("us-east-1")
+ .load()
+ .await,
+ ))
+ .sfs_delete_queue(&config.email_sfs_delete_queue);
+
+ let ctx = context::Context {
+ db,
+ sqs_client: Arc::new(sqs_client),
+ };
+
+ let func = service_fn(move |event: LambdaEvent<EventBridgeEvent>| {
+ let ctx = ctx.clone();
+
+ async move { handler(ctx, event).await }
+ });
+
+ run(func).await
+}
diff --git a/rust/cloud-storage/justfile b/rust/cloud-storage/justfile
index a255dab138..62dd90a769 100644
--- a/rust/cloud-storage/justfile
+++ b/rust/cloud-storage/justfile
@@ -42,6 +42,7 @@ build_lambdas:
just email_refresh_handler/build
just user_link_cleanup_handler/build
just email_scheduled_handler/build
+ just email_sfs_delete_handler/build
# TESTING
diff --git a/rust/cloud-storage/sqs_client/Cargo.toml b/rust/cloud-storage/sqs_client/Cargo.toml
index f0a95c9cbd..f7c44a8dce 100644
--- a/rust/cloud-storage/sqs_client/Cargo.toml
+++ b/rust/cloud-storage/sqs_client/Cargo.toml
@@ -18,15 +18,17 @@ default = [
"gmail",
"organization_retention",
"search",
+ "sfs_delete",
"sfs_uploader",
"upload_extractor",
]
document = []
document_text_extractor = []
-email = ["model", "models_email"]
+email = ["models_email"]
gmail = ["model", "uuid"]
organization_retention = []
search = ["chrono", "model", "models_opensearch", "uuid", "futures"]
+sfs_delete = []
sfs_uploader = []
upload_extractor = []
diff --git a/rust/cloud-storage/sqs_client/src/email.rs b/rust/cloud-storage/sqs_client/src/email.rs
index b61193162d..ff0e44b601 100644
--- a/rust/cloud-storage/sqs_client/src/email.rs
+++ b/rust/cloud-storage/sqs_client/src/email.rs
@@ -2,6 +2,8 @@ use crate::SQS;
use models_email::email::service::backfill::BackfillPubsubMessage;
use models_email::email::service::pubsub::LinkManagerMessage;
use models_email::service::pubsub::{SFSUploaderMessage, ScheduledPubsubMessage};
+use serde::{Deserialize, Serialize};
+use uuid::Uuid;
impl SQS {
pub fn email_link_manager_queue(mut self, link_manager_queue: &str) -> Self {
@@ -25,6 +27,12 @@ impl SQS {
self
}
+ #[cfg(feature = "sfs_delete")]
+ pub fn sfs_delete_queue(mut self, email_sfs_delete_queue: &str) -> Self {
+ self.email_sfs_delete_queue = Some(email_sfs_delete_queue.to_string());
+ self
+ }
+
/// Sends a notification message to the email refresh queue
#[tracing::instrument(skip(self))]
pub async fn enqueue_link_manager_notification(
@@ -76,6 +84,19 @@ impl SQS {
"email_sfs_uploader_queue is not configured"
))
}
+
+ /// Sends a message to the sfs delete queue
+ #[cfg(feature = "sfs_delete")]
+ #[tracing::instrument(skip(self), err)]
+ pub async fn enqueue_sfs_delete_message(
+ &self,
+ message: SFSDeleteMessage,
+ ) -> anyhow::Result<()> {
+ if let Some(queue) = &self.email_sfs_delete_queue {
+ return enqueue_sfs_delete_message(&self.inner, queue, message).await;
+ }
+ anyhow::bail!("email_sfs_delete_queue is not configured")
+ }
}
#[tracing::instrument(skip(sqs_client))]
@@ -155,3 +176,32 @@ pub async fn enqueue_sfs_uploader_message(
Ok(())
}
+
+#[cfg(feature = "sfs_delete")]
+#[tracing::instrument(skip(sqs_client))]
+pub async fn enqueue_sfs_delete_message(
+ sqs_client: &aws_sdk_sqs::Client,
+ queue_url: &str,
+ message: SFSDeleteMessage,
+) -> anyhow::Result<()> {
+ let message_str = serde_json::to_string(&message)?;
+
+ sqs_client
+ .send_message()
+ .queue_url(queue_url)
+ .message_body(message_str)
+ .send()
+ .await?;
+
+ Ok(())
+}
+
+/// The message we send to the sfs_delete
+#[cfg(feature = "sfs_delete")]
+#[derive(Debug, Serialize, Deserialize)]
+pub struct SFSDeleteMessage {
+ /// The ID of the row in email_attachments_sfs
+ pub db_id: Uuid,
+ /// The ID of the item in SFS
+ pub sfs_id: Uuid,
+}
diff --git a/rust/cloud-storage/sqs_client/src/lib.rs b/rust/cloud-storage/sqs_client/src/lib.rs
index ce72851f9f..ce0639b332 100644
--- a/rust/cloud-storage/sqs_client/src/lib.rs
+++ b/rust/cloud-storage/sqs_client/src/lib.rs
@@ -83,6 +83,8 @@ pub struct SQS {
search_event_queue: Option<String>,
#[cfg(feature = "sfs_uploader")]
email_sfs_uploader_queue: Option<String>,
+ #[cfg(feature = "sfs_delete")]
+ email_sfs_delete_queue: Option<String>,
}
impl SQS {
@@ -117,6 +119,8 @@ impl SQS {
search_event_queue: None,
#[cfg(feature = "sfs_uploader")]
email_sfs_uploader_queue: None,
+ #[cfg(feature = "sfs_delete")]
+ email_sfs_delete_queue: None,
}
}
}
diff --git a/rust/cloud-storage/static_file_service_client/src/delete_file.rs b/rust/cloud-storage/static_file_service_client/src/delete_file.rs
index 7a2f5b53e0..6728f4bdff 100644
--- a/rust/cloud-storage/static_file_service_client/src/delete_file.rs
+++ b/rust/cloud-storage/static_file_service_client/src/delete_file.rs
@@ -2,12 +2,15 @@ use super::StaticFileServiceClient;
use anyhow::Result;
impl StaticFileServiceClient {
- pub async fn delete_file(&self, file_id: &str) -> Result<()> {
- self.client
+ /// delete file. propagate error upwards - some callers might see 404 as error, and some as success
+ pub async fn delete_file(&self, file_id: &str) -> Result<reqwest::StatusCode> {
+ let response = self
+ .client
.delete(format!("{}/internal/file/{}", self.url, file_id))
.send()
- .await?;
+ .await?
+ .error_for_status()?;
- Ok(())
+ Ok(response.status())
}
}
diff --git a/rust/cloud-storage/target/lambda/email_scheduled_handler/bootstrap.zip b/rust/cloud-storage/target/lambda/email_scheduled_handler/bootstrap.zip
index 0ae1b88dfa..103b6d9219 100644
Binary files a/rust/cloud-storage/target/lambda/email_scheduled_handler/bootstrap.zip and b/rust/cloud-storage/target/lambda/email_scheduled_handler/bootstrap.zip differ
diff --git a/rust/cloud-storage/target/lambda/email_sfs_delete_handler/bootstrap.zip b/rust/cloud-storage/target/lambda/email_sfs_delete_handler/bootstrap.zip
new file mode 100644
index 0000000000..3f25f0ccaf
Binary files /dev/null and b/rust/cloud-storage/target/lambda/email_sfs_delete_handler/bootstrap.zip differ