import { prisma } from "./db";

export async function recoverStuckJobs() {
  const tenMinutesAgo = new Date(Date.now() - 10 * 60 * 1000);
  const stuck = await prisma.processingJob.updateMany({
    where: {
      status: "processing",
      updatedAt: { lt: tenMinutesAgo },
    },
    data: { status: "queued" },
  });
  if (stuck.count > 0) {
    console.log(`[job-recovery] Reset ${stuck.count} stuck job(s) to queued`);
  }
  return stuck.count;
}
