mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the retention system.
This commit is contained in:
Binary file not shown.
@@ -68,6 +68,7 @@
|
||||
"next": "15.4.2-canary.10",
|
||||
"next-safe-action": "^7.10.8",
|
||||
"next-themes": "^0.4.6",
|
||||
"node-cron": "^4.2.1",
|
||||
"nodemailer": "^7.0.3",
|
||||
"npm-check-updates": "^18.0.1",
|
||||
"pg": "^8.16.0",
|
||||
|
||||
@@ -89,13 +89,13 @@ export const updateProjectAction = userAction
|
||||
if (databasesToRemove.length > 0) {
|
||||
await db.update(drizzleDb.schemas.database).set({ projectId: null }).where(inArray(drizzleDb.schemas.database.id, databasesToRemove));
|
||||
}
|
||||
const slug = slugify(parsedInput.data.name);
|
||||
// const slug = slugify(parsedInput.data.name);
|
||||
|
||||
const [updatedProject] = await db
|
||||
.update(drizzleDb.schemas.project)
|
||||
.set({
|
||||
name: parsedInput.data.name,
|
||||
slug: slug,
|
||||
// slug: slug,
|
||||
})
|
||||
.where(eq(drizzleDb.schemas.project.id, parsedInput.projectId))
|
||||
.returning();
|
||||
|
||||
@@ -27,7 +27,7 @@ export const ProjectForm = (props: projectFormProps) => {
|
||||
const formatDatabasesList = (databases: DatabaseWith[]) => {
|
||||
return databases.map((database) => ({
|
||||
value: database.id,
|
||||
label: `${database.name} (${database.agentDatabaseId}) | ${database.agent.name}`,
|
||||
label: `${database.name} (${database.agentDatabaseId}) | ${database.agent?.name}`,
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
@@ -59,3 +59,4 @@ export const getOrganizationProjectDatabases = async ({organizationSlug, project
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import cron from "node-cron";
|
||||
import {retentionCleanTask} from "@/lib/tasks/project";
|
||||
|
||||
|
||||
export const retentionJob = cron.schedule("* * * * *", async () => {
|
||||
try {
|
||||
console.log("Retention Job : Starting task");
|
||||
await retentionCleanTask();
|
||||
} catch (err) {
|
||||
console.error(`[CRON] Error:`, err);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import {db} from "@/db";
|
||||
import * as drizzleDb from "@/db";
|
||||
|
||||
export const retentionCleanTask = async () => {
|
||||
try {
|
||||
const projects = await db.query.project.findMany();
|
||||
console.log(projects);
|
||||
|
||||
} catch (e: any) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ import {env} from "@/env.mjs";
|
||||
import {db, makeMigration} from "@/db";
|
||||
import {eq} from "drizzle-orm";
|
||||
import * as drizzleDb from "@/db";
|
||||
import cron from "node-cron";
|
||||
import {retentionJob} from "@/lib/tasks";
|
||||
|
||||
|
||||
export async function init() {
|
||||
@@ -11,8 +13,16 @@ export async function init() {
|
||||
await createDefaultOrganization();
|
||||
await createSettingsIfNotExist()
|
||||
console.log("====Initialization completed====");
|
||||
await setupCronJobs()
|
||||
}
|
||||
|
||||
async function setupCronJobs() {
|
||||
console.log("==== Setting up Cron Jobs ====");
|
||||
retentionJob.start();
|
||||
console.log(`==== Cron job started ====`);
|
||||
}
|
||||
|
||||
|
||||
async function createSettingsIfNotExist() {
|
||||
const configSettings = {
|
||||
name: "system",
|
||||
|
||||
@@ -8197,6 +8197,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-cron@npm:^4.2.1":
|
||||
version: 4.2.1
|
||||
resolution: "node-cron@npm:4.2.1"
|
||||
checksum: 10c0/804df01df230e96fd2f8ffcde004f4d5af953bccdf3ccf993dc450526dd65f553a2f2ad4bc0faf55c90c38cbc99c9ddbb88ee16cba3fc6bc74e606da6efb249e
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"node-fetch@npm:^2.7.0":
|
||||
version: 2.7.0
|
||||
resolution: "node-fetch@npm:2.7.0"
|
||||
@@ -8801,6 +8808,7 @@ __metadata:
|
||||
next: "npm:15.4.2-canary.10"
|
||||
next-safe-action: "npm:^7.10.8"
|
||||
next-themes: "npm:^0.4.6"
|
||||
node-cron: "npm:^4.2.1"
|
||||
nodemailer: "npm:^7.0.3"
|
||||
npm-check-updates: "npm:^18.0.1"
|
||||
pg: "npm:^8.16.0"
|
||||
|
||||
Reference in New Issue
Block a user