fix(newsletter): process one user per invocation to respect subrequest limit #74
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "exe-dev-bot/market:fix/newsletter-one-per-invocation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Cloudflare Workers limits each invocation to 50 subrequests (free tier). Each Supabase REST API call counts as one subrequest. Processing a single user requires ~10 subrequests, so the previous approach of processing all users in one invocation hit the limit at ~5 users (out of 17).
See Cloudflare Workers Limits.
Solution
Process one user per invocation via a frequent cron trigger. Each invocation:
At every 5 minutes Mon–Sat, this supports up to 1,728 users/week.
Changes
src/lib/newsletter-delivery.tsfindNextUser()with 7-day dedup guard. Sunday code guard. Cleanup scoped to single user.wrangler.jsonc0 12 * * MON→*/5 * * * MON-SATsrc/worker.tsspecs/003-weekly-newsletter.mdTesting
just start-backendnewsletter_enabledon a test email contact in Supabase Studionewslettertable has one new rownewsletter_send_loghas send entries