MCPcopy Index your code
hub / github.com/simstudioai/sim / cleanupRunChildren

Function cleanupRunChildren

apps/sim/background/cleanup-tasks.ts:41–67  ·  view source on GitHub ↗
(
  workspaceIds: string[],
  retentionDate: Date,
  label: string
)

Source from the content-addressed store, hash-verified

39] as const
40
41async function cleanupRunChildren(
42 workspaceIds: string[],
43 retentionDate: Date,
44 label: string
45): Promise<TableCleanupResult[]> {
46 if (workspaceIds.length === 0) return []
47
48 const runIds = await selectRowsByIdChunks(workspaceIds, (chunkIds, chunkLimit) =>
49 db
50 .select({ id: copilotRuns.id })
51 .from(copilotRuns)
52 .where(
53 and(inArray(copilotRuns.workspaceId, chunkIds), lt(copilotRuns.updatedAt, retentionDate))
54 )
55 .limit(chunkLimit)
56 )
57
58 if (runIds.length === 0) {
59 return RUN_CHILD_TABLES.map((t) => ({ table: `${label}/${t.name}`, deleted: 0, failed: 0 }))
60 }
61
62 const ids = runIds.map((r) => r.id)
63
64 return Promise.all(
65 RUN_CHILD_TABLES.map((t) => deleteRowsById(t.table, t.runIdCol, ids, `${label}/${t.name}`))
66 )
67}
68
69export async function runCleanupTasks(payload: CleanupJobPayload): Promise<void> {
70 const startTime = Date.now()

Callers 1

runCleanupTasksFunction · 0.85

Calls 2

selectRowsByIdChunksFunction · 0.90
deleteRowsByIdFunction · 0.90

Tested by

no test coverage detected