diff --git a/apps/tempo-snapshots-viewer/src/index.ts b/apps/tempo-snapshots-viewer/src/index.ts index 88456b294..9f11a3e6e 100644 --- a/apps/tempo-snapshots-viewer/src/index.ts +++ b/apps/tempo-snapshots-viewer/src/index.ts @@ -315,7 +315,19 @@ app.get('/:chainId/:snapshotName', (context) => ) app.get('/', (context) => handleUI(context.req.raw, context.env)) -export default app +export default { + fetch: app.fetch, + scheduled(_controller: ScheduledController, env: Env, ctx: ExecutionContext) { + ctx.waitUntil(refreshSnapshotCaches(env)) + }, +} + +async function refreshSnapshotCaches(env: Env): Promise { + const snapshots = await getSnapshots(env) + const cache = caches.default + await populateSnapshotCaches(cache, snapshots) + await cache.delete(new Request(CACHE_KEY_UI_HTML, { method: 'GET' })) +} async function serveLatest( { chainId = DEFAULT_CHAIN_ID }: { chainId?: string }, diff --git a/apps/tempo-snapshots-viewer/wrangler.json b/apps/tempo-snapshots-viewer/wrangler.json index a634200bc..a69e8d4f8 100644 --- a/apps/tempo-snapshots-viewer/wrangler.json +++ b/apps/tempo-snapshots-viewer/wrangler.json @@ -31,5 +31,8 @@ "pattern": "snapshots.tempoxyz.dev", "custom_domain": true } - ] + ], + "triggers": { + "crons": ["*/15 * * * *"] + } }