misc: reorganized cron structure and removed unnecessary checks

This commit is contained in:
Sheen Capadngan
2024-06-14 00:58:54 +08:00
parent 4de63b6140
commit 44956c6a37
8 changed files with 27 additions and 29 deletions
+7
View File
@@ -1,3 +1,4 @@
import { CronJob } from "cron";
import { Knex } from "knex";
import { z } from "zod";
@@ -907,6 +908,11 @@ export const registerRoutes = async (
secretSharing: secretSharingService
});
const cronJobs: CronJob[] = [];
if (appCfg.isProductionMode) {
cronJobs.push(rateLimitService.initializeBackgroundSync());
}
server.decorate<FastifyZodProvider["store"]>("store", {
user: userDAL
});
@@ -961,6 +967,7 @@ export const registerRoutes = async (
await server.register(registerV3Routes, { prefix: "/api/v3" });
server.addHook("onClose", async () => {
cronJobs.forEach((job) => job.stop());
await telemetryService.flushAll();
});
};