Files
dckcandClaude Opus 5.5 992e871c56 feat(diigo-cache): refresh each cache every 3 hours
workerd has no cron triggers, but it runs Durable Object alarms, and
the cache DOs already hold their wiring to the webapp: a refresh
scheduled from inside the DO needs no credential outside it (a systemd
timer would need a cache id to call /api with).

A fill that ends (done or failed) sets an alarm 3 hours out; it starts
a fill that refetches every page through the deepest one holding an
item updated in the last 2 days (page 1 at least, where new bookmarks
land). Refetching overwrites pages in place rather than dropping them
first, so a refresh that fails leaves the cache as it was. stopFill now
also stops a finished job's refreshes.

FillStatus gains refetchThrough (optional; additive). Caches whose fill
ended before this get their first refresh alarm when they next wake.

The service starts at boot as well as on the socket: alarms fire only
while workerd runs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-14 23:31:48 -05:00

3.8 KiB

Install, upgrade, roll back

Everything below runs on bldbox. Neither unit has been run under the system manager yet; the flake's smoke check runs the same build under workerd directly.

Once: tailnet HTTPS

In the Tailscale admin console DNS page, enable MagicDNS (on) and HTTPS Certificates (off as of 2026-10-14: tailscale status --json | jq .CertDomains is null). HTTPS matters: the "save to password manager" button uses PasswordCredential, which browsers offer only in a secure context.

Build and check

cd ~/oros-bots/capsite/diigo-cache
nix flake check   # builds, then serves the home page and mints a webapp instance
out=$(nix build --no-link --print-out-paths .#)
nix/probe-unit.sh "$out"   # serves it under the unit's syscall filter: "probe: ok"

The probe catches what the smoke check can't: the nix sandbox has no systemd, so it doesn't apply the unit's SystemCallFilter. The flake only sees files git tracks: git add new files before building.

Install

The service runs whatever /nix/var/nix/profiles/diigo-cache points at, so the profile is also the GC root and the rollback history.

nix-env is spelled out in full because sudo's secure_path leaves out nix's profile.

sudo /nix/var/nix/profiles/default/bin/nix-env -p /nix/var/nix/profiles/diigo-cache --set "$out"
sudo systemctl link /nix/var/nix/profiles/diigo-cache/lib/systemd/system/diigo-cache.{socket,service}
sudo systemctl enable --now diigo-cache.socket diigo-cache.service
sudo tailscale serve --bg --https=443 http://127.0.0.1:8790

tailscale serve --bg persists across reboots in tailscaled's state; tailscale serve status shows it.

Verify

curl -sf https://bldbox.tail09e44.ts.net/ | grep -c _connect   # 1+; first request starts workerd
systemctl status diigo-cache.service

On a 502, make sure tailscale serve finds something on 8790: curl -sI http://127.0.0.1:8790/. (The cache also answers 502 when it can't load a page from diigo; its body then says could not load page.) If workerd crashes on start, systemd stops retrying, then fails the socket too (Result: service-start-limit-hit in systemctl status diigo-cache.socket). After fixing the cause:

sudo systemctl reset-failed diigo-cache.socket diigo-cache.service
sudo systemctl start diigo-cache.socket

From another tailnet device, open https://bldbox.tail09e44.ts.net/. From off the tailnet, the name doesn't resolve and 100.89.146.23 doesn't route.

Upgrade

out=$(nix build --no-link --print-out-paths .#)
nix/probe-unit.sh "$out"
sudo /nix/var/nix/profiles/default/bin/nix-env -p /nix/var/nix/profiles/diigo-cache --set "$out"
sudo systemctl daemon-reload            # in case the units changed
sudo systemctl restart diigo-cache.service

Durable Object state outlives the code: an upgrade whose schema change existing state can't read is a breaking change (see capsite AGENTS.md). Back up first (operate).

Roll back

sudo /nix/var/nix/profiles/default/bin/nix-env -p /nix/var/nix/profiles/diigo-cache --list-generations
sudo /nix/var/nix/profiles/default/bin/nix-env -p /nix/var/nix/profiles/diigo-cache --rollback
sudo systemctl restart diigo-cache.service

Update nixpkgs

nix flake update moves wrangler, and with it workerd. The flake names workerd's version (version in flake.nix); if nixpkgs' wrangler bundles a different one, the build fails with no workerd <version>. Set it to the bundled version, which must be no older than the workers' compatibility_date.

Remove

sudo tailscale serve --https=443 off
sudo systemctl disable --now diigo-cache.socket diigo-cache.service
sudo rm /nix/var/nix/profiles/diigo-cache*   # state in /var/lib/private/diigo-cache stays