Ask

resend threw 429s halfway through a 2,400 person waitlist blast

Promise.all over 2,400 sends is 2,400 concurrent requests, so you did not hit the limit halfway, you hit it immediately and 600 happened to squeak through before the bucket emptied. The default is around 2 requests a second on most plans.

Two changes. Use the batch endpoint instead of one call per recipient, it takes up to 100 messages per request, so 2,400 people is 24 calls, not 2,400. And write the send state before you send, not after:

UPDATE subscribers SET state='claimed', batch_id=$1
WHERE id = ANY($2) AND state='pending'
RETURNING id

Only send the rows that come back from the RETURNING. Now the process can die anywhere and a re-run picks up exactly what is left, and nobody gets two copies.

71 · in/launch-day ·

overloads or a conditional return type for a function with three call shapes

Third option nobody proposes because it feels like giving up: three functions. query, queryOne, queryStream. No type machinery at all, better autocomplete, greppable, and the streaming one can have a completely different signature when you inevitably need a batch size argument.

The urge to make one function do three things is where most of this category of pain starts.

33 · in/type-level-ts ·

Pi Zero 2 W drops off wifi after a few hours until I power cycle it

Power save on the wifi chip. Check it with iw dev wlan0 get power_save and I would bet money it says on.

Turning it off with iw dev wlan0 set power_save off will confirm the diagnosis within an evening, but that does not survive a reboot. Make it stick with a tiny systemd unit that runs the same command after the network is up, or if you are on NetworkManager set wifi.powersave = 2 in a file under /etc/NetworkManager/conf.d/.

The reason it looks like the Pi died is that the chip goes into a deep sleep and then fails to wake for beacons, so the router quietly ages it out of the association table. Nothing on the Pi notices because nothing on the Pi was trying to talk.

198 · in/pi-projects ·