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

Function runCleanupLogs

apps/sim/background/cleanup-logs.ts:425–476  ·  view source on GitHub ↗
(payload: CleanupJobPayload)

Source from the content-addressed store, hash-verified

423}
424
425export async function runCleanupLogs(payload: CleanupJobPayload): Promise<void> {
426 const startTime = Date.now()
427 const { workspaceIds, retentionHours, label, plan, runGlobalHousekeeping } = payload
428
429 const retentionDate = new Date(Date.now() - retentionHours * 60 * 60 * 1000)
430
431 if (workspaceIds.length === 0) {
432 logger.info(`[${label}] No workspaces to process`)
433 if (runGlobalHousekeeping && plan === 'free') {
434 await cleanupFreePlanOrphanedSnapshots(retentionHours)
435 }
436 return
437 }
438
439 logger.info(
440 `[${label}] Cleaning ${workspaceIds.length} workspaces, cutoff: ${retentionDate.toISOString()}`
441 )
442
443 const workflowResults = await cleanupWorkflowExecutionLogs(workspaceIds, retentionDate, label)
444 logger.info(
445 `[${label}] workflow_execution_logs files: ${workflowResults.filesDeleted}/${workflowResults.filesTotal} deleted, ${workflowResults.filesDeleteFailed} failed`
446 )
447 const largeValueResults = await cleanupLargeExecutionValues(workspaceIds, retentionDate, label)
448 logger.info(
449 `[${label}] execution_large_values: ${largeValueResults.largeValuesDeleted}/${largeValueResults.largeValuesTotal} deleted, ${largeValueResults.largeValuesDeleteFailed} failed`
450 )
451 const legacyLargeValueResults = await cleanupLegacyLargeExecutionValues(
452 workspaceIds,
453 retentionDate,
454 label
455 )
456 logger.info(
457 `[${label}] legacy_execution_large_values: ${legacyLargeValueResults.largeValuesDeleted}/${legacyLargeValueResults.largeValuesTotal} deleted, ${legacyLargeValueResults.largeValuesDeleteFailed} failed`
458 )
459 await cleanupLargeValueMetadata(workspaceIds, label)
460
461 await batchDeleteByWorkspaceAndTimestamp({
462 tableDef: jobExecutionLogs,
463 workspaceIdCol: jobExecutionLogs.workspaceId,
464 timestampCol: jobExecutionLogs.startedAt,
465 workspaceIds,
466 retentionDate,
467 tableName: `${label}/job_execution_logs`,
468 })
469
470 if (runGlobalHousekeeping && plan === 'free') {
471 await cleanupFreePlanOrphanedSnapshots(retentionHours)
472 }
473
474 const timeElapsed = (Date.now() - startTime) / 1000
475 logger.info(`[${label}] Job completed in ${timeElapsed.toFixed(2)}s`)
476}
477
478export const cleanupLogsTask = task({
479 id: 'cleanup-logs',

Callers 1

Tested by

no test coverage detected