Reschedule cron job when confirmed subscriber changes frequency #2
Loading…
Reference in a new issue
No description provided.
Delete branch "mailship-e04-frequency-change-updates-db-but-never-re-63d"
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?
mailship-e04
PUT /subscription/emailwith a changed frequency updated the row in the database but never rescheduled the running CronJob. A confirmed subscriber switching from daily to weekly kept the daily cadence until the process restarted.Changes:
src/actions.ts— InregisterSubscription, the existing code distinguished between new/unconfirmed subscriptions (send confirmation email) and already-confirmed ones (skip email). Added anelsebranch that callsworker.registerSubscription(sub)for confirmed subscriptions, which triggersaddJob— stopping the old cron job and creating a new one with the updated frequency.src/worker/email.ts— ExportedgetJobCronSource()to allow test code to inspect the active cron job's expression, enabling a direct assertion thataddJobupdated the schedule.test/reschedule-on-frequency-change.test.js— New failing-before/passing-after test. Creates a confirmed subscription, registers a daily job, then callsregisterSubscriptionwith weekly frequency. Asserts the cron expression changed from0 0 17 * * *(daily) to0 0 17 * * 1(weekly). Before the fix this assertion failed; after the fix it passes.How to test: