* refactor: add cron job core package * docs: add comments to cron validation types * chore(deps): move node-cron dependencies from tasks app to cron-jobs-core package * fix: runOnInit is not running on start and rather on job creation * fix: format issues * fix: build fails when using top level await in cjs * chore: update turbo gen package json typescript version to 5.5.2 * fix: format issue * fix: deepsource issues * chore: update turbo gen package json eslint version to 9.5.0 * chore: fix frozen lockfile and format
30 lines
869 B
TypeScript
30 lines
869 B
TypeScript
import SuperJSON from "superjson";
|
|
|
|
import { sendServerAnalyticsAsync } from "@homarr/analytics";
|
|
import { EVERY_WEEK } from "@homarr/cron-jobs-core/expressions";
|
|
import { db, eq } from "@homarr/db";
|
|
import { serverSettings } from "@homarr/db/schema/sqlite";
|
|
|
|
import { createCronJob } from "~/lib/jobs";
|
|
import type { defaultServerSettings } from "../../../../packages/server-settings";
|
|
|
|
export const analyticsJob = createCronJob("analytics", EVERY_WEEK, {
|
|
runOnStart: true,
|
|
}).withCallback(async () => {
|
|
const analyticSetting = await db.query.serverSettings.findFirst({
|
|
where: eq(serverSettings.settingKey, "analytics"),
|
|
});
|
|
|
|
if (!analyticSetting) {
|
|
return;
|
|
}
|
|
|
|
const value = SuperJSON.parse<(typeof defaultServerSettings)["analytics"]>(analyticSetting.value);
|
|
|
|
if (!value.enableGeneral) {
|
|
return;
|
|
}
|
|
|
|
await sendServerAnalyticsAsync();
|
|
});
|