chore: utils.gc -> cron.daily (#3543)
This commit is contained in:
36
server/routes/api/cron.ts
Normal file
36
server/routes/api/cron.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Context } from "koa";
|
||||
import Router from "koa-router";
|
||||
import { AuthenticationError } from "@server/errors";
|
||||
import CleanupDeletedDocumentsTask from "@server/queues/tasks/CleanupDeletedDocumentsTask";
|
||||
import CleanupDeletedTeamsTask from "@server/queues/tasks/CleanupDeletedTeamsTask";
|
||||
import CleanupExpiredFileOperationsTask from "@server/queues/tasks/CleanupExpiredFileOperationsTask";
|
||||
import InviteReminderTask from "@server/queues/tasks/InviteReminderTask";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
const cronHandler = async (ctx: Context) => {
|
||||
const { token, limit = 500 } = ctx.body as { token?: string; limit: number };
|
||||
|
||||
if (process.env.UTILS_SECRET !== token) {
|
||||
throw AuthenticationError("Invalid secret token");
|
||||
}
|
||||
|
||||
await CleanupDeletedDocumentsTask.schedule({ limit });
|
||||
|
||||
await CleanupExpiredFileOperationsTask.schedule({ limit });
|
||||
|
||||
await CleanupDeletedTeamsTask.schedule({ limit });
|
||||
|
||||
await InviteReminderTask.schedule();
|
||||
|
||||
ctx.body = {
|
||||
success: true,
|
||||
};
|
||||
};
|
||||
|
||||
router.post("cron.:period", cronHandler);
|
||||
|
||||
// For backwards compatibility
|
||||
router.post("utils.gc", cronHandler);
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user