Skip to content

fix: the weekly digest never sent - #10

Open
scobb wants to merge 1 commit into
mainfrom
fix/weekly-digest-cron
Open

scobb wants to merge 1 commit into
mainfrom
fix/weekly-digest-cron

Conversation

@scobb

@scobb scobb commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Problem

wrangler.toml had two crons at the same minute: 0 9 * * * (alerts) and 0 9 * * 1 (weekly digest). Cloudflare fires only one trigger per minute. On all five Mondays checked (2026-09-14 → 10-12), Workers analytics shows only the daily one, so runWeeklyDigests has never run in production.

Fix

  • The digest runs from the daily trigger when it's Monday (UTC). The 0 9 * * 1 trigger is removed from all four wrangler configs.
  • A test fails if any config gets two triggers on the same minute again.

Changes before the first real send

Enabling it as-is would have sent 64 emails a week:

  • One email per user. Users with several active sites get one summary table: pageviews, visitors, week-over-week change and top source per site, each linking to its dashboard. Single-site users get the existing detailed digest. Previously the paying customer would have gotten 19 separate emails every Monday.
  • No all-zero digests. Sites with no pageviews in either week are left out, and a user with none gets no email.
  • Reserved test addresses skipped (RFC 2606/6761: example.com/net/org, .test, .invalid, .example, localhost). 36 of the 44 would-be recipients are smoke…@example.com accounts, and mailing them only produces bounces.
  • HTML escaping in the digest for site names, paths, referrers and insight text.

Expected first send, Monday 2026-10-19 09:00 UTC: 5 emails. One is the paying customer's 18-site summary, one is Beam's own account, and three are free users with active sites.

Tests

  • New test/weekly-digest.test.ts (8 tests), run on real SQL via node:sqlite.
  • Removed the traffic-alerts test for the deleted weekly trigger.
  • Mutation-checked: the old scheduled.ts fails the Monday, multi-site and escaping tests. Dropping the Monday condition fails the Tuesday test. Removing the reserved-address or zero-traffic filters fails their tests.
  • Full suite passes: 165 pass, 4 skipped.

🤖 Generated with Claude Code

The digest had its own cron, '0 9 * * 1', on the same minute as the daily
'0 9 * * *'. Cloudflare fires only one trigger per minute, and on every
Monday checked (2026-09-14 through 10-12) it was the daily one, so
runWeeklyDigests never ran. It now runs from the daily trigger on Mondays,
and the second trigger is gone from all four wrangler configs.

Turning it on as written would have sent 64 emails a week, so before the
first real send:
- one email per user: several active sites get a summary table, instead of
  19 separate emails to the paying customer every Monday
- sites with no pageviews in either week are left out, and a user with none
  gets nothing
- RFC 2606 reserved addresses are skipped; 36 of the 44 would-be recipients
  are smoke-test accounts at example.com, which would only bounce
- site names, paths, referrers and insights are HTML-escaped

Monday's first run should send 5 emails.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

1 participant