feat: add Job Monitor page with cron job logging and Selenium queue status

This commit is contained in:
ff
2026-04-13 00:32:18 -04:00
parent 034c0fa993
commit 11a6d2e5a7
85 changed files with 3046 additions and 12 deletions

View File

@@ -0,0 +1,61 @@
import { prisma as db } from "@repo/db/client";
export type CronJobStatus = "success" | "failed" | "skipped";
export interface CronJobLogEntry {
id: number;
jobName: string;
status: string;
startedAt: Date;
completedAt: Date | null;
durationMs: number | null;
errorMessage: string | null;
}
export const cronJobLogStorage = {
async createJobLog(
jobName: string,
startedAt: Date
): Promise<CronJobLogEntry> {
return db.cronJobLog.create({
data: { jobName, status: "running", startedAt },
});
},
async completeJobLog(
id: number,
status: CronJobStatus,
completedAt: Date,
errorMessage?: string
): Promise<CronJobLogEntry> {
const durationMs = completedAt.getTime() - (await db.cronJobLog.findUniqueOrThrow({ where: { id } })).startedAt.getTime();
return db.cronJobLog.update({
where: { id },
data: { status, completedAt, durationMs, errorMessage: errorMessage ?? null },
});
},
async getRecentLogs(limit = 50): Promise<CronJobLogEntry[]> {
return db.cronJobLog.findMany({
orderBy: { startedAt: "desc" },
take: limit,
});
},
async getLastRunPerJob(): Promise<CronJobLogEntry[]> {
// Get the most recent log entry for each distinct jobName
const jobs = await db.cronJobLog.findMany({
distinct: ["jobName"],
orderBy: { startedAt: "desc" },
});
return jobs;
},
async getFailedLogs(limit = 20): Promise<CronJobLogEntry[]> {
return db.cronJobLog.findMany({
where: { status: "failed" },
orderBy: { startedAt: "desc" },
take: limit,
});
},
};