Retry Resend calls on 429 and throttle Newsletter Archive lookups; v2.7.1
Publish Container / build (push) Successful in 15m57s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
nmemmertandClaude Sonnet 5.5 committed 2026-10-01 09:14:49 -04:00
1 parent 66cdb9c4c9
commit dad0e5691e
4 files changed
+37 -17

No files matched your search

+9 -3
View File
@@ -4,6 +4,7 @@ import { requireAdminAuth } from '../auth.js'
import { state } from '../state.js'
import { queueNewsletterIssuesWrite } from '../data.js'
import { escapeHtml } from '../helpers.js'
import { resendRetry } from '../email.js'
const BASE = 'https://versebyversewithnate.us'
const NEW_EPISODE_TOPIC_NAME = 'new episode'
@@ -117,8 +118,8 @@ export function register(app) {
try {
const resend = new Resend(process.env.RESEND_API_KEY)
const [{ data: topicsData, error: topicsError }, { data: listData, error: listError }] = await Promise.all([
resend.topics.list(),
resend.broadcasts.list(),
resendRetry(() => resend.topics.list()),
resendRetry(() => resend.broadcasts.list()),
])
if (topicsError) throw new Error(topicsError.message)
if (listError) throw new Error(listError.message)
@@ -126,7 +127,12 @@ export function register(app) {
const newEpisodeTopic = (topicsData?.data ?? []).find(t => String(t.name || '').trim().toLowerCase() === NEW_EPISODE_TOPIC_NAME)
const sentBroadcasts = (listData?.data ?? []).filter(b => b.status === 'sent')
const details = await Promise.all(sentBroadcasts.map(b => resend.broadcasts.get(b.id)))
// Fetch a few at a time so a long broadcast history can't exceed Resend's requests-per-second limit.
const details = []
for (let i = 0; i < sentBroadcasts.length; i += 4) {
const chunk = await Promise.all(sentBroadcasts.slice(i, i + 4).map(b => resendRetry(() => resend.broadcasts.get(b.id))))
details.push(...chunk)
}
const broadcasts = details.map(({ data }, i) => {
const summary = sentBroadcasts[i]