import { getScheduleDeleteCronJobRunDetailsSql } from '@supabase/pg-meta' import { CheckCircle2, XCircle } from 'lucide-react' import { Button, Dialog, DialogContent, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, DialogTrigger, Progress, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' import { Admonition } from 'ui-patterns/admonition' import { CodeBlock } from 'ui-patterns/CodeBlock' import { CLEANUP_INTERVALS } from './CronJobsTab.constants' import { useCronJobsCleanupActions, type BatchDeletionProgress, } from './CronJobsTab.useCleanupActions' import { InlineLinkClassName } from '@/components/ui/InlineLink' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' interface CronJobRunDetailsOverflowNoticeV2Props { queryCost?: number refetchJobs: () => void } export const CronJobRunDetailsOverflowNotice = (props: CronJobRunDetailsOverflowNoticeV2Props) => { return ( } >

Last run for each cron job omitted due to high query cost

) } const CronJobRunDetailsOverflowDialog = ({ queryCost, refetchJobs, }: CronJobRunDetailsOverflowNoticeV2Props) => { const { data: project } = useSelectedProjectQuery() const { cleanupInterval, cleanupState, isScheduling, isScheduleSuccess, setCleanupInterval, runBatchedDeletion, scheduleCleanup, cancelDeletion, } = useCronJobsCleanupActions({ projectRef: project?.ref, connectionString: project?.connectionString, }) const isDeleting = cleanupState.status === 'deleting' const isDeleteSuccess = cleanupState.status === 'delete-success' const isDeleteError = cleanupState.status === 'delete-error' const isBusy = isDeleting || isScheduling const canSchedule = isDeleteSuccess || isScheduleSuccess return ( event.preventDefault()} > Last run for cron jobs omitted for overview

The dashboard fetches data for the cron jobs overview by running a join between the{' '} cron.job and{' '} cron.job_run_details tables to show each cron job's latest run.

However, the join was skipped as the{' '} estimated query cost

Estimated cost: {queryCost?.toLocaleString()}

Determined via the EXPLAIN command

{' '} exceeds safety thresholds, likely due to the size of{' '} cron.job_run_details table.

Suggested steps

We recommend removing the old run history now, then scheduling a cron job that keeps trimming the cron.job_run_details table automatically. This also prevents unnecessary bloat on the database.

Step 1: Delete older entries

{isDeleting ? ( ) : isDeleteSuccess ? ( ) : isDeleteError ? ( runBatchedDeletion(cleanupInterval)} /> ) : (
)}

Step 2: Schedule an automated cleanup

{!canSchedule ? (

Complete step 1 to enable scheduling a daily cleanup job.

) : isScheduleSuccess ? ( ) : ( <> )}
) } interface DeletionProgressProps { progress: BatchDeletionProgress onCancel: () => void } const DeletionProgress = ({ progress, onCancel }: DeletionProgressProps) => { const { currentBatch, totalBatches, totalRowsDeleted } = progress const percentComplete = totalBatches > 0 ? Math.min(Math.round((currentBatch / totalBatches) * 100), 100) : 0 return (
{percentComplete}% ({currentBatch}/{totalBatches} batches)
Deleted {totalRowsDeleted.toLocaleString()} rows so far...
) } interface DeletionSuccessProps { totalRowsDeleted: number } const DeletionSuccess = ({ totalRowsDeleted }: DeletionSuccessProps) => (
Successfully deleted {totalRowsDeleted.toLocaleString()} rows.
) interface DeletionErrorProps { error: string onRetry: () => void } const DeletionError = ({ error, onRetry }: DeletionErrorProps) => (
Deletion failed: {error}
) const ScheduleSuccess = () => (
Daily cleanup job scheduled successfully.

New cleanup job should now be visible in the cron jobs overview.

)