Vendors
How the register is put together, what has to be done by hand in the Cloudflare dashboard, and how to get it back if the database is lost.
One database, three deployments, all from this repository.
| Piece | Where it lives | What it does |
|---|---|---|
The sitek8srunbooks |
Cloudflare Pages, from site/ on the production branch |
Serves every page here, and — new — the register's API from functions/ |
The remindersdcbar-key-dates-reminders |
Worker, from workers/reminders/ |
Runs daily, works out what is due, sends one digest through SendGrid |
Mail indcbar-key-dates-inbound |
Worker, from workers/inbound/ |
Turns mail to add@keydates.dcbar.org into entries. Optional. |
lib/ sits outside functions/ deliberately. Pages
turns every file under functions/ into a route, so a helper
module placed there would be reachable as a URL.
Pages cannot run on a schedule — Cron Triggers are a Workers feature, and Pages Functions only run in response to a request. Email Workers are likewise a Workers thing. The site could have been rebuilt as a single Worker serving static assets, which would have collapsed all three into one deployment, but that would have meant moving a live hostname with Cloudflare Access attached to it. Three small deployments against one database was the cheaper trade.
All three bind dcbar-key-dates as KEYDATES. There
is no copy and no sync. If the reminder worker and the page ever disagree
about what is in the register, something is bound to the wrong database
— check database_id in all three
wrangler.toml files before looking anywhere else.
In order. Steps 1 to 5 give a working register; 6 gives it reminders. Mail in is section 4 and can wait indefinitely.
From the repository root, with Wrangler signed in to the DC Bar account:
npx wrangler d1 create dcbar-key-dates
It prints a [[d1_databases]] block containing the real
database_id. That value is the one piece of configuration that
cannot be written down in advance.
Replace PASTE_THE_DATABASE_ID_HERE with the id from step 1 in
each of:
wrangler.toml
workers/reminders/wrangler.toml
workers/inbound/wrangler.toml
All three get the same value. Leaving the placeholder in place makes the deploy fail with an invalid-database-id error, which is the better of the two failures — the other being a site that deploys and whose form returns a 500 to whoever tries it first.
# --remote is what makes this run against the real database rather
# than a local file. Forgetting it is the most common mistake here:
# it succeeds, says so, and changes nothing that matters.
npx wrangler d1 execute dcbar-key-dates --remote --file=db/schema.sql
npx wrangler d1 execute dcbar-key-dates --remote --file=db/seed.sql
schema.sql is safe to re-run. seed.sql is not
— running it twice gives two of every row.
Check it took:
npx wrangler d1 execute dcbar-key-dates --remote \
--command "SELECT id, due_date, title FROM key_dates ORDER BY due_date"
Pages builds from the production branch. Pushing the new
functions/ directory and the amended wrangler.toml
is what turns the API on.
Until now Pages took its build settings from the dashboard and ignored
wrangler.toml, because the file had no
pages_build_output_dir key. It has one now, so from this
deploy onwards the file wins. The values match what the dashboard already
had — build output site, no build command — so
nothing changes in practice. It matters because any future change to those
settings must be made in the file; a change made in the dashboard will be
overwritten by the next deploy.
From anywhere that can reach the site:
curl -s https://docs.dcbar.org/api/key-dates | head -40
JSON with today, count and six seeded entries
means the binding is live. An HTML 404 means the
functions/ directory did not get deployed — check it is
at the repository root and not inside site/.
cd workers/reminders
npx wrangler deploy
npx wrangler secret put SENDGRID_API_KEY
The key is pasted at the prompt, not stored in any file. It needs only the Mail Send permission — make a restricted-access key rather than reusing a full-access one, and add it to the register with its own expiry date while it is in front of you.
MAIL_FROM in workers/reminders/wrangler.toml must
be a verified sender in SendGrid or the send fails with a 403. Single Sender
Verification is enough; domain authentication is better, and
dcbar.org's DNS is already at Cloudflare so the records are
three clicks.
The worker has a read-only HTTP handler that reports exactly what the next scheduled run would send, sending nothing and recording nothing:
cd workers/reminders
npx wrangler dev --remote
Then open the address it prints. To test the send path end to end, add an entry dated 20 days out and trigger the schedule:
npx wrangler dev --remote --test-scheduled
curl "http://localhost:8787/__scheduled?cron=0+12+*+*+*"
A reminder system that has never delivered a message is not a reminder
system. Add an entry dated exactly 20 days out, run the scheduled test
above, and confirm the mail lands in itdiagnostics@dcbar.org
before considering any of this done.
20, 10 and 5 days before the date, then every day once it has passed.
One message a day at most. Anything past its date appears in every run until someone moves it forward or closes it, so an overlooked expiry becomes steadily harder to ignore rather than scrolling away.
crons = ["0 12,13 * * *"]. Cron Triggers are UTC only, and
08:00 in Washington is 12:00 UTC during daylight saving and 13:00 UTC
otherwise. Both are scheduled; the worker checks the local hour and the
wrong one exits immediately. A single fixed UTC time would send at 07:00 for
half the year, which is survivable, and would be the kind of detail nobody
remembers when the clocks change.
reminder_log's primary key is
(key_date_id, due_date, threshold). The due_date
is in there deliberately: when a renewal is done and the date moves forward,
the key changes and the 20/10/5 reminders fire again for the new date. Keyed
on the entry and threshold alone, every future renewal of that row would
have been silent.
The daily overdue nag uses overdue:YYYY-MM-DD as its threshold,
so one-per-day falls out of the primary key rather than needing a query to
work out.
The log is written after SendGrid accepts the message. A failed send leaves the log untouched and tomorrow's run tries again — a day late rather than never. The other order would mark an entry as reminded about on the strength of an email that never left.
Optional, and the only part that needs DNS changes. Leave it until the rest is running.
Cloudflare Email Routing requires the receiving zone's MX records to point
at Cloudflare. dcbar.org's MX point at Microsoft 365 and must
stay there — that is everyone's mail. A subdomain gets its own MX
records, so keydates.dcbar.org can receive at Cloudflare
while every other address at DC Bar is untouched. The address becomes
add@keydates.dcbar.org, not add@dcbar.org.
keydates.dcbar.org to Cloudflare and enable Email Routing on it. The dashboard supplies the MX and TXT records to create.cd workers/inbound, then npm install, then npx wrangler deploy.add@keydates.dcbar.org → Send to a Worker → dcbar-key-dates-inbound.
Deploying the worker on its own receives nothing. The routing rule in step 3
is what connects the address to it, and it is made in the dashboard —
there is no key in wrangler.toml for an inbound route.
To: add@keydates.dcbar.org
Subject: anything
Title: VPN appliance support contract
Date: 2027-03-15
Category: Support contract
Owner: Tim Ramlogan
Vendor: Cisco
Notes: No TAC and no RMA if this lapses. Quote is with procurement.
Only Title and Date are required, and if
Title is missing the subject line is used instead — so
Subject: Firewall licence 2027-06-30 with an empty body also
works, which is the realistic thing to type on a phone. Everything after
Notes: runs to the end of the message.
Mail from outside dcbar.org is refused, as is anything failing
DMARC. A message that cannot be understood bounces with the reason
rather than disappearing — someone who sends a malformed entry and
hears nothing will assume it worked and find out eleven months later that it
did not, which is the exact failure this register exists to prevent.
There is no confirmation on success. The entry appearing on the page is the confirmation, and sending one would need an outbound binding and a verified destination for no real gain.
D1 keeps point-in-time history, but a copy that lives somewhere else is worth having for something this small.
npx wrangler d1 export dcbar-key-dates --remote --output=key-dates-backup.sql
The whole register is a few kilobytes. Running this before any schema change costs nothing and removes the only genuinely unrecoverable mistake available here.
D1 can restore to any moment in the last 30 days without a backup file. Use it after an accident rather than trying to reconstruct by hand:
npx wrangler d1 time-travel info dcbar-key-dates
npx wrangler d1 time-travel restore dcbar-key-dates --timestamp=2026-10-14T12:00:00Z
Every insert, update and delete is written to
key_dates_history by database triggers — not by the API,
so a change made with wrangler d1 execute at two in the morning
is recorded too. Deletes store the whole row as JSON, so the register can be
reconstructed from the history table alone.
# everything that has ever happened to entry 1
npx wrangler d1 execute dcbar-key-dates --remote \
--command "SELECT at, action, actor, snapshot FROM key_dates_history WHERE key_date_id = 1 ORDER BY seq"
# what was deleted, and when
npx wrangler d1 execute dcbar-key-dates --remote \
--command "SELECT at, key_date_id, snapshot FROM key_dates_history WHERE action = 'delete' ORDER BY seq DESC LIMIT 20"
No email means nothing is due. It also means the worker is broken, the SendGrid key was revoked, the sender lost its verification, or nobody ever added anything. These are indistinguishable from the inbox. The register contains a row — Quarterly check: key dates reminders are still arriving — which is the only thing that tells them apart. When it comes round, open the worker's logs, confirm it has been running, and move the date forward three months rather than closing it.
The SendGrid API key this depends on is the same credential the cluster's alerting depends on. If it lapses, both stop — including the reminders that would have warned you. Its expiry belongs in the register, and it is seeded there as an entry to go and find.
There is no separate write permission. The office network is in a Cloudflare Access bypass range, so for anyone at a desk in the building there is no sign-in and no authenticated identity to record — which is why the form asks for a name rather than taking one from the Access header. When the header is present, for someone working remotely, it overrides the typed name, so the field cannot be used to impersonate anyone from outside the office. Cross-origin writes are rejected outright.
The D1 binding is declared at the top level of wrangler.toml,
which means preview deployments get the same database as production. For a
register of this size that is the right trade — a second database
would need the seed data maintained twice and would make preview a
misleading place to test. But a preview deployment is a live write path:
do not use one to try out a destructive change.
Everything is YYYY-MM-DD, and every day-count is anchored to
Eastern local time. Without that, for the five hours after 19:00 Eastern
the register would be a day ahead of the people reading it and a reminder
due “in 5 days” would go out on day 6. If dates ever look off
by one, this is where to look.