mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 09:14:54 +10:00
feat: run tasks at startup
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import prisma from "../internal/db/database";
|
import prisma from "~/server/internal/db/database";
|
||||||
|
|
||||||
export default defineNitroPlugin(async (_nitro) => {
|
export default defineNitroPlugin(async (_nitro) => {
|
||||||
// Ensure system user exists
|
// Ensure system user exists
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import prisma from "../internal/db/database";
|
import prisma from "~/server/internal/db/database";
|
||||||
|
|
||||||
export default defineNitroPlugin(async (_nitro) => {
|
export default defineNitroPlugin(async (_nitro) => {
|
||||||
const userCount = await prisma.user.count({
|
const userCount = await prisma.user.count({
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export default defineNitroPlugin(async (_nitro) => {
|
||||||
|
// all tasks we should run on server boot
|
||||||
|
await Promise.all([
|
||||||
|
runTask("cleanup:invitations"),
|
||||||
|
runTask("cleanup:sessions"),
|
||||||
|
]);
|
||||||
|
});
|
||||||
@@ -5,6 +5,8 @@ export default defineTask({
|
|||||||
name: "cleanup:invitations",
|
name: "cleanup:invitations",
|
||||||
},
|
},
|
||||||
async run() {
|
async run() {
|
||||||
|
console.log("[Task cleanup:invitations]: Cleaning invitations");
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
await prisma.invitation.deleteMany({
|
await prisma.invitation.deleteMany({
|
||||||
@@ -15,6 +17,7 @@ export default defineTask({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("[Task cleanup:invitations]: Done");
|
||||||
return { result: true };
|
return { result: true };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import sessionHandler from "~/server/internal/session";
|
|||||||
|
|
||||||
export default defineTask({
|
export default defineTask({
|
||||||
meta: {
|
meta: {
|
||||||
name: "cleanup:invitations",
|
name: "cleanup:sessions",
|
||||||
},
|
},
|
||||||
async run() {
|
async run() {
|
||||||
|
console.log("[Task cleanup:sessions]: Cleaning up sessions");
|
||||||
await sessionHandler.cleanupSessions();
|
await sessionHandler.cleanupSessions();
|
||||||
|
console.log("[Task cleanup:sessions]: Done");
|
||||||
return { result: true };
|
return { result: true };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user