Add scheduled Square catalog refresh via Docker sidecar

Catalog data only refreshed on first boot, admin button click, or
checkout retry — nothing kept it fresh on a schedule despite the
cache-refresh endpoint being built for cron use. A Next instrumentation
hook was tried first but broke the build (middleware.ts forces
instrumentation.ts into the same edge bundle, which can't resolve
fs/path/crypto). Using a lightweight cron sidecar in the compose stack
instead, so it ships with the deployment regardless of host.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
chris 2026-08-19 11:27:49 -04:00
parent 219256be55
commit 5b9524e1d9
2 changed files with 22 additions and 1 deletions

View File

@ -98,6 +98,27 @@ services:
timeout: 10s timeout: 10s
retries: 3 retries: 3
# ── Scheduled Square catalog refresh ─────────────────────────────────────────
# Hits estore's cache-refresh endpoint on a timer so catalog/pricing edits made
# in Square show up without a redeploy or manual admin-panel refresh. Runs as
# part of the stack itself, so it works on any host this compose file is deployed to.
estore-cache-refresh:
image: alpine:3.20
container_name: bpb-estore-cache-refresh
env_file: ./estore/.env
depends_on:
estore:
condition: service_healthy
entrypoint: >
sh -c "
apk add --no-cache curl >/dev/null 2>&1;
while true; do
curl -sf -X POST http://estore:3000/shop/api/cache/refresh -H \"Authorization: Bearer $$CACHE_REFRESH_SECRET\" || echo 'cache refresh failed';
sleep 21600;
done
"
restart: unless-stopped
# ── OSRM download (runs once, exits) ───────────────────────────────────────── # ── OSRM download (runs once, exits) ─────────────────────────────────────────
# Downloads the PBF map file into the shared volume if not already present. # Downloads the PBF map file into the shared volume if not already present.
osrm-download: osrm-download:

File diff suppressed because one or more lines are too long