feat: customer detail page, size snapshots table, Spaces provisioning, Redis status cache
Some checks failed
Build & Release / build (push) Has been cancelled

This commit is contained in:
Ryan Moon
2026-04-03 20:07:18 -05:00
parent bc9d7b464c
commit b11b51aa1e
11 changed files with 832 additions and 273 deletions

33
src/lib/cache.ts Normal file
View File

@@ -0,0 +1,33 @@
import Redis from "ioredis";
import { config } from "./config";
// Manager uses the managed Valkey with "mgr:" prefix so it doesn't collide with customer keys
export const cache = new Redis(config.managedValkeyUrl, {
keyPrefix: "mgr:",
lazyConnect: true,
enableReadyCheck: false,
});
const STATUS_TTL = 120; // seconds
export async function getCachedStatus(slug: string): Promise<{ data: any; cachedAt: string } | null> {
try {
const raw = await cache.get(`status:${slug}`);
if (!raw) return null;
return JSON.parse(raw);
} catch {
return null;
}
}
export async function setCachedStatus(slug: string, data: any): Promise<void> {
try {
await cache.set(`status:${slug}`, JSON.stringify({ data, cachedAt: new Date().toISOString() }), "EX", STATUS_TTL);
} catch {}
}
export async function invalidateCachedStatus(slug: string): Promise<void> {
try {
await cache.del(`status:${slug}`);
} catch {}
}

View File

@@ -8,6 +8,8 @@ export const config = {
doadminDbUrl: process.env.DOADMIN_DATABASE_URL!,
jwtSecret: process.env.JWT_SECRET!,
managedValkeyUrl: process.env.MANAGED_VALKEY_URL!,
spacesBucket: process.env.SPACES_BUCKET ?? "lunarfront-data",
spacesRegion: process.env.SPACES_REGION ?? "nyc3",
};
for (const [key, val] of Object.entries(config)) {

View File

@@ -10,7 +10,7 @@ function token() {
return readFileSync(SA_TOKEN_PATH, "utf-8").trim();
}
async function k8sFetch(path: string, options: RequestInit = {}, allowStatuses: number[] = []) {
export async function k8sFetch(path: string, options: RequestInit = {}, allowStatuses: number[] = []) {
const res = await fetch(`${K8S_API}${path}`, {
...options,
headers: {