mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: clean up failed and ongoing backups
This commit is contained in:
@@ -8,21 +8,36 @@ const log = logger.child({module: "tasks/cleaning"});
|
||||
|
||||
export const backupCleanTask = async () => {
|
||||
try {
|
||||
const backups = await db.query.backup.findMany({
|
||||
const ongoingBackups = await db.query.backup.findMany({
|
||||
where: and(
|
||||
isNotNull(drizzleDb.schemas.backup.deletedAt),
|
||||
eq(drizzleDb.schemas.backup.status, "ongoing")
|
||||
)
|
||||
});
|
||||
log.debug(`Backups to clean: ${backups.length}`);
|
||||
log.debug(`Backups to clean: ${ongoingBackups.length}`);
|
||||
|
||||
for (const backup of backups) {
|
||||
for (const backup of ongoingBackups) {
|
||||
await db.update(drizzleDb.schemas.backup).set(withUpdatedAt({
|
||||
status: "failed",
|
||||
}))
|
||||
.where(eq(drizzleDb.schemas.backup.id, backup.id));
|
||||
}
|
||||
|
||||
const failedBackups = await db.query.backup.findMany({
|
||||
where: and(
|
||||
isNull(drizzleDb.schemas.backup.deletedAt),
|
||||
eq(drizzleDb.schemas.backup.status, "failed")
|
||||
)
|
||||
});
|
||||
log.debug(`Failed backups to clean: ${failedBackups.length}`);
|
||||
|
||||
for (const backup of failedBackups) {
|
||||
await db.update(drizzleDb.schemas.backup).set(withUpdatedAt({
|
||||
deletedAt: new Date(),
|
||||
}))
|
||||
.where(eq(drizzleDb.schemas.backup.id, backup.id));
|
||||
}
|
||||
|
||||
} catch (e: any) {
|
||||
log.error({name: "backupCleanTask", error: e},`Backup cleanup failed`);
|
||||
throw e;
|
||||
|
||||
Reference in New Issue
Block a user