From 01154c0856e5e1e6bffc818be07ff5f0c7448ce7 Mon Sep 17 00:00:00 2001 From: martbost Date: Wed, 28 Oct 2026 14:34:31 -0500 Subject: [PATCH] Member update emails: claim the send slot before building the recipient list (the Sendy opt-in checks take minutes). On 2026-10-28 a retried POL Miner launch email raced the first one: both passed the 'already running' check, 475 members got it twice; stopped by a restart, the rest went out once. A second send now gets 'A send is already running' immediately. Co-Authored-By: Claude Opus 5.5 --- updates.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/updates.js b/updates.js index e8f136e..0295e3b 100644 --- a/updates.js +++ b/updates.js @@ -80,12 +80,17 @@ async function send(input, opts) { return { ok: true, test: true, to }; } if (running) return { error: 'A send is already running (' + running.sent + ' of ' + running.total + '). Wait for it to finish.' }; - const kind = AUDIENCES[input.audience] ? input.audience : 'optin'; + // claim the slot BEFORE the slow recipient list (Sendy opt-in checks take minutes): two sends raced on 2026-10-28 and 475 members got the POL Miner email twice + running = { sent: 0, total: 0, building: true }; + let kind, list; + try { + kind = AUDIENCES[input.audience] ? input.audience : 'optin'; unknownOptins = 0; - let list = await recipients(kind); + list = await recipients(kind); if (Array.isArray(input.to) && input.to.length) { const want = new Set(input.to.map(e => String(e).toLowerCase())); const all = await R.accounts.listAll(20000); list = all.filter(a => a.email && want.has(String(a.email).toLowerCase())); } // explicit list (repairs) if (unknownOptins && !(input.to && input.to.length)) console.log('updates: Sendy gave no answer for', unknownOptins, 'members; they were left out of this send'); - if (!list.length) return { error: 'Nobody in that audience.' }; + if (!list.length) { running = null; return { error: 'Nobody in that audience.' }; } + } catch (e) { running = null; throw e; } const rec = { id: Date.now().toString(36), ts: Date.now(), subject: compose(input, null).subject, noteIds, audience: kind, total: list.length, sent: 0, skipped: 0, failed: 0, status: 'running', unknown: unknownOptins, recipients: list.map(a => a.email) }; const l = log(); l.sends.unshift(rec); l.sends = l.sends.slice(0, 50); saveLog(l); running = rec; (async () => {