This commit is contained in:
Carl-Gerhard Lindesvärd
2025-12-17 22:59:11 +01:00
parent bc84404235
commit ccff90829b
33 changed files with 1882 additions and 1083 deletions

View File

@@ -34,6 +34,11 @@ export async function bootCron() {
type: 'flushSessions',
pattern: 1000 * 10,
},
{
name: 'insightsDaily',
type: 'insightsDaily',
pattern: '0 2 * * *',
},
];
if (process.env.SELF_HOSTED && process.env.NODE_ENV === 'production') {
@@ -44,12 +49,6 @@ export async function bootCron() {
});
}
jobs.push({
name: 'insightsDaily',
type: 'insightsDaily',
pattern: '0 2 * * *', // 2 AM daily
});
logger.info('Updating cron jobs');
const jobSchedulers = await cronQueue.getJobSchedulers();

View File

@@ -79,11 +79,6 @@ async function start() {
await bootCron();
} else {
logger.warn('Workers are disabled');
// Start insights worker
const insightsWorker = new Worker(insightsQueue.name, insightsProjectJob, {
connection: getRedisQueue(),
});
}
await createInitialSalts();

View File

@@ -16,7 +16,7 @@ import { insightsQueue } from '@openpanel/queue';
import type { Job } from 'bullmq';
const defaultEngineConfig = {
keepTopNPerModuleWindow: 5,
keepTopNPerModuleWindow: 20,
closeStaleAfterDays: 7,
dimensionBatchSize: 50,
globalThresholds: {
@@ -24,8 +24,6 @@ const defaultEngineConfig = {
minAbsDelta: 80,
minPct: 0.15,
},
enableExplain: false,
explainTopNPerProjectPerDay: 3,
};
export async function insightsDailyJob(job: Job<CronQueuePayload>) {
@@ -63,9 +61,12 @@ export async function insightsProjectJob(
config: defaultEngineConfig,
});
const projectCreatedAt = await insightStore.getProjectCreatedAt(projectId);
await engine.runProject({
projectId,
cadence: 'daily',
now: new Date(date),
projectCreatedAt,
});
}