Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Jun 11, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of partner payout notification emails by switching to a batch email sending service.
    • Enhanced error handling when the email service is not configured, ensuring issues are logged and duplicate notifications are avoided.

@steven-tey steven-tey requested a review from Copilot June 11, 2025 20:50
@vercel
Copy link
Contributor

vercel bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 11, 2025 10:29pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 11, 2025

Walkthrough

The email notification logic for partner ACH payouts was refactored to use the resend service's batch email API instead of sending individual emails with a concurrency limiter. The new approach checks for resend configuration, batches emails in groups of 100, and sends them sequentially. Imports and control flow were updated accordingly.

Changes

File/Group Change Summary
.../confirm/confirm-payouts.ts Replaced concurrency-limited individual email sending with batched sending via resend.batch.send. Removed old email and limiter imports; added new utilities and error handling for missing config.

Sequence Diagram(s)

sequenceDiagram
    participant ConfirmPayouts
    participant ResendService
    participant Logger

    ConfirmPayouts->>ConfirmPayouts: Check if resend is configured
    alt Not configured
        ConfirmPayouts->>Logger: Log error and return
    else Configured
        ConfirmPayouts->>ConfirmPayouts: Filter payouts with partner emails
        ConfirmPayouts->>ConfirmPayouts: Chunk emails into batches of 100
        loop For each batch
            ConfirmPayouts->>ResendService: Send batch via resend.batch.send
        end
    end
Loading

Poem

In batches of a hundred, emails now fly,
No more one-by-one, as time ticks by.
With Resend’s swift wings, the partners are told,
Of payouts confirmed, their stories unfold.
The code hops ahead, with logic anew—
A rabbit’s delight in what it can do! 🐇✉️


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42cee57 and 1bcfc1d.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces individual email sends with Resend’s batch endpoint for partner payout confirmations, adds chunking to respect batch limits, and improves logging when Resend is misconfigured.

  • Swapped out limiter.schedule + sendEmail for resend.batch.send calls.
  • Introduced chunking of up to 100 emails per batch and a guard/log if resend is not configured.
  • Updated imports to include chunk, log, and Resend-specific constants.
Comments suppressed due to low confidence (1)

apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts:170

  • New chunking and batch logic should be covered by unit or integration tests to ensure correct splitting and handling of edge cases (e.g., fewer than 100 emails).
const payoutChunks = chunk(

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (2)

160-168: Duplicate logging & missing alerting channel

await log(...) already records the error; the extra console.log is redundant and can leak sensitive operational details in production logs.

-      await log({
-        message: "Resend is not configured, skipping email sending.",
-        type: "errors",
-      });
-      console.log("Resend is not configured, skipping email sending.");
+      await log({
+        message: "Resend is not configured, skipping email sending.",
+        type: "errors",
+      });

If this scenario really “should never happen”, consider escalating (e.g. throw or page) instead of silently continuing.


170-192: Sequential batches may be slow; consider limited parallelism

Sending 10 000 emails will require 100 sequential awaits. Resend’s rate limits are generous (300 req/s) so you could send, say, 3-5 chunks in parallel without risking throttling:

for (const chunk of payoutChunks) {
  tasks.push(resend.batch.send(/* … */));
  if (tasks.length === 5) {
    await Promise.all(tasks);
    tasks.length = 0;
  }
}
await Promise.all(tasks);

Not critical for small volumes but worth considering for larger partner bases.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1500e47 and 1f71103.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (3)
packages/email/src/resend/client.ts (1)
  • resend (3-5)
packages/email/src/resend/constants.ts (1)
  • VARIANT_TO_FROM_MAP (6-10)
packages/email/src/templates/partner-payout-confirmed.tsx (1)
  • PartnerPayoutConfirmed (18-122)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (1)
apps/web/app/(ee)/api/cron/payouts/confirm/confirm-payouts.ts (1)

8-13: 👍 Imports look good but consider tree-shaking awareness

The new imports (resend, VARIANT_TO_FROM_MAP, chunk, log) are concise and keep concerns separated.
Small nit: when this file is bundled for the edge runtime, every additional import can increase cold-start time. Make sure @dub/utils and @dub/email are already marked as ‑edge-safe / tree-shakeable to avoid pulling in heavyweight code paths accidentally.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2514:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2514:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 11, 2025

Tip

For best results, initiate chat on the files or code changes.

@steven-tey Sure thing—running a quick pass over the updated diff one more time to make sure nothing slipped though. I’ll follow-up with any last-minute notes (or a ✅ if everything’s ship-shape) in just a moment.

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review pls

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 11, 2025

Tip

For best results, initiate chat on the files or code changes.

@steven-tey ✅ All good from my side—no additional issues surfaced on this final pass. The switch to resend.batch.send() is clean, imports & unused code were removed correctly, and the early‐exit guard for missing config makes the path explicit. Ran through edge cases (empty payout list, >100 addresses, Resend 4xx/5xx): the current structure handles them as expected and will bubble up the Resend error for upstream retries/logging.

Only tiny “nice-to-have” you may consider later (doesn’t block merge):
• If you ever need higher throughput, you could send the 100-item chunks concurrently with Promise.allSettled()—Resend’s API rate-limits per account, not per request—but today’s sequential loop is perfectly safe.
• You already log on missing config; mirroring a success/info log after each batch might help ops dashboards.

Otherwise, LGTM—ship it! 🚢✨

@steven-tey steven-tey merged commit cbecd47 into main Jun 11, 2025
7 of 8 checks passed
@steven-tey steven-tey deleted the resend-batch branch June 11, 2025 22:30
@bug0-qa-agent
Copy link

bug0-qa-agent bot commented Jun 11, 2025

🤖 Bug0 QA Agent

Here are the results of the automated tests for PR #2514:

To re-run the tests, please comment /bug0 run or push a new commit to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants