AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(app): log received shutdown signal and pause between file-cleanup iterations (#16516)
Chaker Atallahf370253250a8
diff --git a/packages/server/api/src/app/file/file.service.ts b/packages/server/api/src/app/file/file.service.tsindex 8c0a81e210f..b41dc42d3f1 100644--- a/packages/server/api/src/app/file/file.service.ts+++ b/packages/server/api/src/app/file/file.service.ts@@ -1,5 +1,6 @@import { Readable } from 'node:stream'import { buffer as streamToBuffer } from 'node:stream/consumers'+import { setTimeout as delay } from 'node:timers/promises'import { ActivepiecesError, apId, assertNotNullOrUndefined, ErrorCode, isMultipartFile, isNil, ProjectId } from '@activepieces/core-utils'import { File, FileCompression, FileId, FileLocation, FileType, Project } from '@activepieces/shared'import dayjs from 'dayjs'@@ -22,6 +23,7 @@ const IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp',export const fileRepo = repoFactory<File>(FileEntity)const EXECUTION_DATA_RETENTION_DAYS = system.getNumberOrThrow(AppSystemProp.EXECUTION_DATA_RETENTION_DAYS)const FILE_CLEANUP_STATEMENT_TIMEOUT_MS = 5 * 60 * 1000+const FILE_CLEANUP_PAUSE_BETWEEN_ITERATIONS_MS = 1000type BaseFile = Pick<File, 'id' | 'projectId' | 'platformId' | 'type' | 'fileName' | 'compression' | 'size' | 'metadata' | 'created' | 'updated'>@@ -225,6 +227,7 @@ export const fileService = (log: FastifyBaseLogger) => ({counts: affected,type,}, '[FileService#deleteStaleBulk] iteration completed')+ await delay(FILE_CLEANUP_PAUSE_BETWEEN_ITERATIONS_MS)}}}diff --git a/packages/server/api/src/main.ts b/packages/server/api/src/main.tsindex e10f9a41ba6..bdeff3e1b2b 100644--- a/packages/server/api/src/main.ts+++ b/packages/server/api/src/main.ts@@ -30,11 +30,12 @@ const start = async (app: FastifyInstance): Promise<void> => {let shuttingDown = false-const stop = async (app: FastifyInstance): Promise<void> => {+const stop = async ({ app, signal }: { app: FastifyInstance, signal: NodeJS.Signals }): Promise<void> => {if (shuttingDown) returnshuttingDown = truetry {+ app.log.info({ signal }, '[main#stop] Received shutdown signal, stopping server gracefully')await app.close()await evlogSetup.flush()process.exit(0)@@ -66,11 +67,11 @@ const main = async (): Promise<void> => {const app = await setupServer()process.on('SIGINT', async () => {- await stop(app).catch((e) => system.globalLogger().error({ err: e }, '[main#stop] Failed to stop server'))+ await stop({ app, signal: 'SIGINT' }).catch((e) => system.globalLogger().error({ err: e }, '[main#stop] Failed to stop server'))})process.on('SIGTERM', async () => {- await stop(app).catch((e) => system.globalLogger().error({ err: e }, '[main#stop] Failed to stop server'))+ await stop({ app, signal: 'SIGTERM' }).catch((e) => system.globalLogger().error({ err: e }, '[main#stop] Failed to stop server'))})await start(app)