diff --git a/src/server/cronjob/index.ts b/src/server/cronjob/index.ts index 41cc6d9..6bf172e 100644 --- a/src/server/cronjob/index.ts +++ b/src/server/cronjob/index.ts @@ -3,6 +3,7 @@ import { logger } from '../utils/logger'; import { prisma } from '../model/_client'; import dayjs from 'dayjs'; import { Prisma } from '@prisma/client'; +import { env } from '../utils/env'; type WebsiteEventCountSqlReturn = { workspace_id: string; @@ -139,6 +140,10 @@ async function statDailyUsage() { * Clear over 2 week data */ async function clearMonitorDataDaily() { + if (env.disableAutoClear) { + return; + } + const date = dayjs().subtract(2, 'weeks').toDate(); logger.info('Start clear monitor data before:', date.toISOString()); const res = await prisma.monitorData.deleteMany({ diff --git a/src/server/utils/env.ts b/src/server/utils/env.ts index 9f04644..c72dd1f 100644 --- a/src/server/utils/env.ts +++ b/src/server/utils/env.ts @@ -16,6 +16,7 @@ export const env = { process.env.DISABLE_ANONYMOUS_TELEMETRY ), customTrackerScriptName: process.env.CUSTOM_TRACKER_SCRIPT_NAME, + disableAutoClear: checkEnvTrusty(process.env.DISABLE_AUTO_CLEAR), // disable auto clear old data cronjob }; export function checkEnvTrusty(env: string | undefined): boolean {