Skip to content

Commit ddbdacb

Browse files
committed
improvement(cleanup): chunk-index labels, clarify upper-bound failure counter
Addresses Greptile review feedback: - Disambiguate downstream logs when a plan splits into multiple workspace chunks (e.g. 'free/1', 'free/2') - Document that deleteRowsById's failed counter is an upper bound (chunk rolls back to 0 deletes on error)
1 parent 3f3f200 commit ddbdacb

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

apps/sim/lib/billing/cleanup-dispatcher.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,14 @@ async function buildCleanupChunks(jobType: CleanupJobType): Promise<CleanupJobPa
213213
.filter((row) => planByWorkspaceId.get(row.id) === plan)
214214
.map((row) => row.id)
215215
if (workspaceIds.length === 0) continue
216-
for (const ws of chunkArray(workspaceIds, WORKSPACES_PER_CLEANUP_CHUNK)) {
217-
chunks.push({ plan, workspaceIds: ws, retentionHours, label: plan })
216+
const planChunks = chunkArray(workspaceIds, WORKSPACES_PER_CLEANUP_CHUNK)
217+
for (const [idx, ws] of planChunks.entries()) {
218+
chunks.push({
219+
plan,
220+
workspaceIds: ws,
221+
retentionHours,
222+
label: planChunks.length > 1 ? `${plan}/${idx + 1}` : plan,
223+
})
218224
}
219225
}
220226

apps/sim/lib/cleanup/batch-delete.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,12 @@ export async function deleteRowsById(
240240
.returning({ id: idCol })
241241
result.deleted += deleted.length
242242
} catch (error) {
243+
// Upper bound: Postgres rolls back the chunk on error, so actual deletes = 0,
244+
// but we can't tell which IDs in the chunk would have matched. The next cron
245+
// run picks up whatever's still expired, so this only inflates the metric.
243246
result.failed += chunkIds.length
244247
logger.error(
245-
`[${tableName}] Delete chunk ${chunkIdx + 1}/${chunks.length} failed (${chunkIds.length} rows):`,
248+
`[${tableName}] Delete chunk ${chunkIdx + 1}/${chunks.length} failed (up to ${chunkIds.length} rows):`,
246249
{ error }
247250
)
248251
}

0 commit comments

Comments
 (0)