Files
fredy/lib/services/crons/tracker-cron.js

25 lines
737 B
JavaScript
Raw Normal View History

2025-12-11 10:40:55 +01:00
/*
* Copyright (c) 2026 by Christian Kellner.
2025-12-11 10:40:55 +01:00
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
*/
2025-09-13 17:06:18 +02:00
import cron from 'node-cron';
import { inDevMode } from '../../utils.js';
import { trackMainEvent } from '../tracking/Tracker.js';
import { getSettings } from '../storage/settingsStorage.js';
2025-09-13 17:06:18 +02:00
async function runTask() {
const settings = await getSettings();
2025-09-13 17:06:18 +02:00
//make sure to only send tracking events if the user gave us the green light and we are not in dev mode
if (settings.analyticsEnabled && !inDevMode()) {
2025-09-13 17:06:18 +02:00
await trackMainEvent();
}
}
export async function initTrackerCron() {
//run directly on start
await runTask();
// then every 6 hours
cron.schedule('0 */6 * * *', runTask);
}