From 5938c38349f25037df9f14b1f06a60e42e78f965 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 25 Apr 2024 00:19:04 +0800 Subject: [PATCH] feat: add env DISABLE_AUTO_CLEAR --- src/server/cronjob/index.ts | 5 +++++ src/server/utils/env.ts | 1 + 2 files changed, 6 insertions(+) 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 {