Skip to content

Commit 078e466

Browse files
fix(cron): retry and serialize cleanup dispatch on the task definition
1 parent 4d0974d commit 078e466

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎apps/sim/app/api/cron/cleanup-file-versions/route.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type NextRequest, NextResponse } from 'next/server'
33
import { verifyCronAuth } from '@/lib/auth/internal'
44
import { getJobQueue } from '@/lib/core/async-jobs'
55
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
6+
import { CLEANUP_DISPATCH_MAX_ATTEMPTS } from '@/background/cleanup-dispatch'
67

78
export const dynamic = 'force-dynamic'
89

@@ -21,7 +22,7 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
2122
'cleanup-dispatch',
2223
{ jobType: 'cleanup-file-versions' },
2324
{
24-
maxAttempts: 1,
25+
maxAttempts: CLEANUP_DISPATCH_MAX_ATTEMPTS,
2526
jobId: `cleanup-dispatch:cleanup-file-versions:${scheduleWindow}`,
2627
name: 'File version cleanup dispatch',
2728
concurrencyKey: 'cleanup-dispatch:cleanup-file-versions',

‎apps/sim/background/cleanup-dispatch.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ export interface CleanupDispatchPayload {
55
jobType: CleanupJobType
66
}
77

8+
/** Attempts per dispatch. A rerun only re-triggers chunks that delete already-expired data. */
9+
export const CLEANUP_DISPATCH_MAX_ATTEMPTS = 3
10+
811
/**
912
* Resolves a retention job's workspace scope and fans out its per-chunk cleanup runs. The scan
10-
* covers every active workspace, so it runs here rather than inside the cron request.
13+
* covers every active workspace, so it runs here rather than inside the cron request. One
14+
* dispatch at a time per job type: the route keys runs by `concurrencyKey`.
1115
*/
1216
export const cleanupDispatchTask = task({
1317
id: 'cleanup-dispatch',
14-
retry: { maxAttempts: 1 },
18+
queue: { concurrencyLimit: 1 },
19+
retry: { maxAttempts: CLEANUP_DISPATCH_MAX_ATTEMPTS },
1520
run: ({ jobType }: CleanupDispatchPayload) => dispatchCleanupJobs(jobType),
1621
})

0 commit comments

Comments
 (0)