chore: parallelize follow-up email sending with Promise.all (#1239)
* chore: parallelize follow-up email sending with Promise.all
Previously, follow-up emails were sent sequentially inside a for...of loop, leading to slower execution. This change uses Promise.all to send emails in parallel, significantly improving the speed of the process.
* feat(emails): implement batch follow-up emails with rate limiting
Improve the follow-up email system by:
- Optimizing database queries to select only necessary email fields
- Implementing batched email sending (80 emails per batch)
- Adding proper rate limit detection and handling
- Improving error logging and recovery
* fix: improve follow-up email sending reliability and error handling
The changes improve email delivery reliability by:
- Enhancing email validation with stronger type guards
- Adding proper break statement for rate limit errors to prevent wasteful API calls
- Simplifying error flow control with early returns and consistent error handling
- Restructuring try/catch blocks for better exception management
- Improving TypeScript type safety with more specific error handling
These modifications ensure the system gracefully handles rate limiting while providing clearer logs for debugging. Email validation now properly checks for empty strings, preventing attempts to send to invalid addresses.
* minor change
* fix(followup-emails): added type checking for email as string
Initially, we were not checking type of email and calling trim() on it, this improvision check whether email is really a string and then calls trim() on it.
* minor change: removed un-necassary type checking for email
* ci: apply automated fixes
---------
Co-authored-by: Thibault Le Ouay <thibaultleouay@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
authored by