Files
erika/lib/admin/service-health.ts

61 lines
1.5 KiB
TypeScript

import "server-only";
import { sql } from "drizzle-orm";
import { db } from "@/db";
import { getDiscordMemberCount } from "@/lib/followers/discord";
import { getRobloxFollowerCount } from "@/lib/followers/roblox";
import { getTiktokProfile } from "@/lib/followers/tiktok";
import { getYoutubeSubscriberCount } from "@/lib/followers/youtube";
import { getRedisClient } from "@/lib/redis";
import {
collectServiceHealth,
createCachedHealthReader,
type ServiceHealthProbe,
} from "./service-health-core";
const probes: ServiceHealthProbe[] = [
{
id: "database",
label: "PostgreSQL",
category: "core",
check: async () => {
await db.execute(sql`select 1`);
return true;
},
},
{
id: "redis",
label: "Redis / realtime",
category: "core",
check: async () => (await (await getRedisClient()).ping()) === "PONG",
},
{
id: "youtube",
label: "YouTube",
category: "integration",
check: async () => (await getYoutubeSubscriberCount()) !== null,
},
{
id: "tiktok",
label: "TikTok",
category: "integration",
check: async () => (await getTiktokProfile()).followerCount !== null,
},
{
id: "discord",
label: "Discord",
category: "integration",
check: async () => (await getDiscordMemberCount()) !== null,
},
{
id: "roblox",
label: "Roblox",
category: "integration",
check: async () => (await getRobloxFollowerCount()) !== null,
},
];
export const getAdminServiceHealth = createCachedHealthReader(() =>
collectServiceHealth(probes),
);