radio: quiet hours for reminders (default 23:00-07:30 Amsterdam, RADIO_QUIET_HOURS overrides)
All checks were successful
Deploy production / deploy (push) Successful in 1m21s

This commit is contained in:
2026-10-26 17:18:59 +00:00
parent 95a8b76562
commit f954881bcc
6 changed files with 74 additions and 5 deletions

View File

@@ -9,22 +9,30 @@
*
* Reminders go to RADIO_NTFY_URL (an ntfy topic URL, optional RADIO_NTFY_TOKEN), passed in with
* `docker exec --env-file ~/.config/radio.env`. radio.reminders makes every reminder fire once.
* RADIO_QUIET_HOURS (default 23:00-07:30, "off" to disable) skips reminders sent in that window.
*/
import postgres from 'postgres';
import * as sat from 'satellite.js';
import {
ISS_DOWNLINK_HZ,
ISS_MIN_EL,
QUIET_HOURS,
REMIND_MINUTES,
compass,
fmtTime,
formatFreq,
occurrences
inQuiet,
occurrences,
parseQuiet
} from '../src/lib/radio/index';
if (!process.env.DB_URL) throw new Error('DB_URL is required');
const sql = postgres(process.env.DB_URL, { max: 2, onnotice: () => {} });
const mode = process.argv[2] ?? 'remind';
// Quiet hours (Amsterdam): reminders whose send time falls inside are skipped. "off" disables.
const QUIET = parseQuiet(process.env.RADIO_QUIET_HOURS ?? QUIET_HOURS);
const sendAt = (at: Date) => new Date(at.getTime() - REMIND_MINUTES * 60_000);
const quiet = (at: Date) => inQuiet(sendAt(at), QUIET);
const PAGE = 'https://stanrunge.dev/trackers/radio';
// Gouda (approx), 0 m.
@@ -237,6 +245,7 @@ async function remind() {
const now = new Date();
const list = await due(now, new Date(now.getTime() + REMIND_MINUTES * 60_000));
for (const r of list) {
if (quiet(r.at)) continue;
const [claimed] = await sql`INSERT INTO radio.reminders (kind, ref_id, at)
VALUES (${r.kind}, ${r.refId}, ${r.at}) ON CONFLICT DO NOTHING RETURNING at`;
if (!claimed) continue;
@@ -255,8 +264,11 @@ try {
else if (mode === 'remind') await remind();
else if (mode === 'upcoming') {
const now = new Date();
console.log(`quiet hours: ${QUIET?.label ?? 'off'} (Europe/Amsterdam, by send time)`);
for (const r of await due(now, new Date(now.getTime() + 86_400_000)))
console.log(`${r.at.toISOString()} ${r.kind}: ${r.title} | ${r.message}`);
console.log(
`${quiet(r.at) ? 'QUIET-SKIP' : 'SEND '} at ${fmtTime(sendAt(r.at))} ${r.kind}: ${r.title}`
);
} else throw new Error(`unknown mode ${mode} (iss | remind | upcoming)`);
} finally {
await sql.end();