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:
@@ -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}`,
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
+2
-1
@@ -58,4 +58,5 @@ export const getOrganizationProjectDatabases = async ({organizationSlug, project
|
||||
cause: e,
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user