mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: stuck backups with ongoing status but deleted, for legacy.
This commit is contained in:
@@ -19,8 +19,6 @@ export const useUpdateCheck = () => {
|
|||||||
staleTime: 1000 * 60 * 60,
|
staleTime: 1000 * 60 * 60,
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("newRelease", newRelease);
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!newRelease) return;
|
if (!newRelease) return;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import {db} from "@/db";
|
||||||
|
import {and, eq, isNotNull, isNull} from "drizzle-orm";
|
||||||
|
import * as drizzleDb from "@/db";
|
||||||
|
import {withUpdatedAt} from "@/db/utils";
|
||||||
|
|
||||||
|
export const backupCleanTask = async () => {
|
||||||
|
try {
|
||||||
|
const backups = await db.query.backup.findMany({
|
||||||
|
where: and(
|
||||||
|
isNotNull(drizzleDb.schemas.backup.deletedAt),
|
||||||
|
eq(drizzleDb.schemas.backup.status, "ongoing")
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`Backups to clean: ${backups.length}`);
|
||||||
|
|
||||||
|
for (const backup of backups) {
|
||||||
|
await db.update(drizzleDb.schemas.backup).set(withUpdatedAt({
|
||||||
|
status: "failed",
|
||||||
|
}))
|
||||||
|
.where(eq(drizzleDb.schemas.backup.id, backup.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("Backup cleanup failed:", e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import cron from "node-cron";
|
import cron from "node-cron";
|
||||||
import {retentionCleanTask} from "@/lib/tasks/database";
|
import {retentionCleanTask} from "@/lib/tasks/database";
|
||||||
import {env} from "@/env.mjs";
|
import {env} from "@/env.mjs";
|
||||||
|
import {backupCleanTask} from "@/lib/tasks/cleaning";
|
||||||
|
|
||||||
|
|
||||||
export const retentionJob = cron.schedule(env.RETENTION_CRON, async () => {
|
export const retentionJob = cron.schedule(env.RETENTION_CRON, async () => {
|
||||||
@@ -10,4 +11,13 @@ export const retentionJob = cron.schedule(env.RETENTION_CRON, async () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`[CRON] Error:`, err);
|
console.error(`[CRON] Error:`, err);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const cleaningJob = cron.schedule("* * * * *", async () => {
|
||||||
|
try {
|
||||||
|
console.log("Cleaning Job : Starting task");
|
||||||
|
await backupCleanTask();
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`[CRON] Error:`, err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
@@ -3,7 +3,6 @@ import {getMasterServerKeyContent} from "@/features/keys/keys.action";
|
|||||||
|
|
||||||
export async function generateEdgeKey(serverUrl: string, agentId: string): Promise<string> {
|
export async function generateEdgeKey(serverUrl: string, agentId: string): Promise<string> {
|
||||||
const masterKey = getMasterServerKeyContent()
|
const masterKey = getMasterServerKeyContent()
|
||||||
console.log("Master server key: ", masterKey)
|
|
||||||
const edgeKeyData = {
|
const edgeKeyData = {
|
||||||
serverUrl,
|
serverUrl,
|
||||||
agentId,
|
agentId,
|
||||||
|
|||||||
+8
-1
@@ -2,7 +2,7 @@ import {env} from "@/env.mjs";
|
|||||||
import {db, makeMigration} from "@/db";
|
import {db, makeMigration} from "@/db";
|
||||||
import {eq} from "drizzle-orm";
|
import {eq} from "drizzle-orm";
|
||||||
import * as drizzleDb from "@/db";
|
import * as drizzleDb from "@/db";
|
||||||
import {retentionJob} from "@/lib/tasks";
|
import {cleaningJob, retentionJob} from "@/lib/tasks";
|
||||||
import {generateRSAKeys, getOrCreateMasterKey} from "@/utils/rsa-keys";
|
import {generateRSAKeys, getOrCreateMasterKey} from "@/utils/rsa-keys";
|
||||||
import {StorageProviderKind} from "@/features/storages/types";
|
import {StorageProviderKind} from "@/features/storages/types";
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ export async function init() {
|
|||||||
await createSettingsIfNotExist()
|
await createSettingsIfNotExist()
|
||||||
console.log("====Initialization completed====");
|
console.log("====Initialization completed====");
|
||||||
await setupCronJobs()
|
await setupCronJobs()
|
||||||
|
await setupCleaningJobs()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupCronJobs() {
|
async function setupCronJobs() {
|
||||||
@@ -25,6 +26,12 @@ async function setupCronJobs() {
|
|||||||
console.log("==== Cron job started ====");
|
console.log("==== Cron job started ====");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function setupCleaningJobs() {
|
||||||
|
console.log("==== Setting up Cleaning Jobs ====");
|
||||||
|
cleaningJob.start();
|
||||||
|
console.log("==== Cleaning job started ====");
|
||||||
|
}
|
||||||
|
|
||||||
async function createSettingsIfNotExist() {
|
async function createSettingsIfNotExist() {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const systemSettingsValues = {
|
const systemSettingsValues = {
|
||||||
|
|||||||
Reference in New Issue
Block a user