Files
sofa/app/api/admin/jobs/trigger/route.ts
T
jake 107eb9a9e7 Overhaul system health section with job trigger controls and live timestamps
Rebuild the background jobs card as a sortable table showing each job's
schedule, last run time (live-updating via a new useTimeAgo hook), last
duration, and a manual trigger button backed by a new POST
/api/admin/jobs/trigger route. Extract StatusDot into a shared
component. Add cronToHuman() to display schedule patterns as readable
strings (e.g. "Every 6h", "Daily at 03:00"). Replace static
formatDistanceToNow calls throughout the health section with a
LiveTimeAgo component that refreshes every 30 seconds. Also swap a
handful of section icons for better visual matches across settings cards.
2026-03-05 11:52:37 -05:00

32 lines
938 B
TypeScript

import { headers } from "next/headers";
import { NextResponse } from "next/server";
import { auth } from "@/lib/auth/server";
import { triggerJob } from "@/lib/cron";
export async function POST(request: Request) {
const session = await auth.api.getSession({ headers: await headers() });
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (session.user.role !== "admin") {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
const body = await request.json();
const jobName = body?.jobName;
if (!jobName || typeof jobName !== "string") {
return NextResponse.json(
{ error: "Missing jobName in request body" },
{ status: 400 },
);
}
const triggered = await triggerJob(jobName);
if (!triggered) {
return NextResponse.json({ error: "Job not found" }, { status: 404 });
}
return NextResponse.json({ ok: true, jobName });
}