Harden dev startup and web typecheck

This commit is contained in:
dirtydishes 2025-12-27 21:20:22 -05:00
parent a94baa745c
commit f2f12f2ebe
4 changed files with 65 additions and 5 deletions

View file

@ -31,6 +31,33 @@ const envSchema = z.object({
const env = readEnv(envSchema);
const retry = async <T>(
label: string,
attempts: number,
delayMs: number,
task: () => Promise<T>
): Promise<T> => {
let lastError: unknown;
for (let attempt = 1; attempt <= attempts; attempt += 1) {
try {
return await task();
} catch (error) {
lastError = error;
logger.warn(`${label} attempt failed`, {
attempt,
error: error instanceof Error ? error.message : String(error)
});
if (attempt < attempts) {
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
}
}
throw lastError ?? new Error(`${label} failed after retries`);
};
type ClusterState = {
contractId: string;
startTs: number;
@ -174,7 +201,9 @@ const run = async () => {
database: env.CLICKHOUSE_DATABASE
});
await ensureFlowPacketsTable(clickhouse);
await retry("clickhouse table init", 20, 500, async () => {
await ensureFlowPacketsTable(clickhouse);
});
const subscription = await subscribeJson(
js,