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 () => {