feat: add env DISABLE_AUTO_CLEAR

This commit is contained in:
moonrailgun 2024-04-25 00:19:04 +08:00
parent fe0b596d29
commit 5938c38349
2 changed files with 6 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import { logger } from '../utils/logger';
import { prisma } from '../model/_client'; import { prisma } from '../model/_client';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { Prisma } from '@prisma/client'; import { Prisma } from '@prisma/client';
import { env } from '../utils/env';
type WebsiteEventCountSqlReturn = { type WebsiteEventCountSqlReturn = {
workspace_id: string; workspace_id: string;
@ -139,6 +140,10 @@ async function statDailyUsage() {
* Clear over 2 week data * Clear over 2 week data
*/ */
async function clearMonitorDataDaily() { async function clearMonitorDataDaily() {
if (env.disableAutoClear) {
return;
}
const date = dayjs().subtract(2, 'weeks').toDate(); const date = dayjs().subtract(2, 'weeks').toDate();
logger.info('Start clear monitor data before:', date.toISOString()); logger.info('Start clear monitor data before:', date.toISOString());
const res = await prisma.monitorData.deleteMany({ const res = await prisma.monitorData.deleteMany({

View File

@ -16,6 +16,7 @@ export const env = {
process.env.DISABLE_ANONYMOUS_TELEMETRY process.env.DISABLE_ANONYMOUS_TELEMETRY
), ),
customTrackerScriptName: process.env.CUSTOM_TRACKER_SCRIPT_NAME, 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 { export function checkEnvTrusty(env: string | undefined): boolean {