import { cronJobs, makeFunctionReference } from "convex/server";

// Reconciles attempts whose worker lease expired (crash/restart). The target
// is referenced by string so this file does not depend on regenerated codegen.
const reconcileRef = makeFunctionReference<
  "mutation",
  Record<string, never>,
  { reconciled: number } | null
>("workExecution:reconcileExpiredAttempts");
const reconcileConversationTurnsRef = makeFunctionReference<
  "mutation",
  Record<string, never>,
  { reconciled: number }
>("conversationMessages:reconcileExpiredTurns");

const crons = cronJobs();

crons.interval(
  "reconcile expired work attempts",
  { seconds: 30 },
  reconcileRef
);
crons.interval(
  "reconcile expired conversation turns",
  { seconds: 30 },
  reconcileConversationTurnsRef
);

export default crons;
