-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Test 100K plan with AWS SQS (#493)
- Loading branch information
Showing
7 changed files
with
969 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Tables } from "@/supabase/database.types"; | ||
import { SQSClient, SendMessageBatchCommand } from "@aws-sdk/client-sqs"; | ||
import type { CheckEmailInput } from "@reacherhq/api"; | ||
import type { WebhookExtra } from "./webhook/route"; | ||
import { getWebappURL } from "@/util/helpers"; | ||
|
||
// Initialize the SQS client | ||
const sqsClient = new SQSClient({ region: "eu-west-3" }); | ||
|
||
const queueUrl = | ||
"https://sqs.eu-west-3.amazonaws.com/430118836964/check-email-queue"; | ||
|
||
// Matches this Rust struct: | ||
// https://github.com/reacherhq/check-if-email-exists/blob/v0.10.1/backend/src/worker/do_work.rs#L34 | ||
type CheckEmailTask = { | ||
input: CheckEmailInput; | ||
job_id: { | ||
bulk: number; | ||
}; | ||
webhook?: { | ||
on_each_email?: { | ||
url: string; | ||
headers: Record<string, string | undefined>; | ||
extra: WebhookExtra; | ||
}; | ||
}; | ||
}; | ||
|
||
export const sendEmailsToSQS = async ( | ||
bulkEmails: Tables<"bulk_emails">[], | ||
userId: string | ||
) => { | ||
const command = new SendMessageBatchCommand({ | ||
QueueUrl: queueUrl, | ||
Entries: bulkEmails.map((bulkEmail) => ({ | ||
Id: bulkEmail.id.toString(), | ||
MessageBody: JSON.stringify(bulkEmailToTask(bulkEmail, userId)), | ||
})), | ||
}); | ||
|
||
const response = await sqsClient.send(command); | ||
console.log( | ||
"[💪 SQS] Message sent successfully:", | ||
JSON.stringify(response) | ||
); | ||
}; | ||
|
||
function bulkEmailToTask( | ||
bulkEmail: Tables<"bulk_emails">, | ||
userId: string | ||
): CheckEmailTask { | ||
return { | ||
input: { | ||
to_email: bulkEmail.email, | ||
}, | ||
job_id: { | ||
bulk: bulkEmail.bulk_job_id, | ||
}, | ||
webhook: { | ||
on_each_email: { | ||
url: `${getWebappURL()}/api/v1/bulk/webhook`, | ||
headers: { | ||
"x-reacher-secret": process.env.RCH_HEADER_SECRET, | ||
}, | ||
extra: { | ||
bulkEmailId: bulkEmail.id, | ||
userId, | ||
endpoint: "/v1/bulk", | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.