mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix: log job when storage file missing for restoration
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import * as drizzleDb from "@/db";
|
||||
import {db as dbClient} from "@/db";
|
||||
import {eq} from "drizzle-orm";
|
||||
import {logger} from "@/lib/logger";
|
||||
import {sendNotificationsBackupRestore} from "@/features/notifications/utils/notifications.helpers";
|
||||
|
||||
const log = logger.child({module: "api/agent/status/restoration"});
|
||||
|
||||
export async function handleFailedRestoration(restorationId: string, databaseId: string, reason: string): Promise<void> {
|
||||
try {
|
||||
await dbClient
|
||||
.insert(drizzleDb.schemas.jobLog)
|
||||
.values({
|
||||
backupId: null,
|
||||
restorationId,
|
||||
loggedAt: new Date(),
|
||||
entryType: "log",
|
||||
level: "error",
|
||||
message: reason,
|
||||
command: null,
|
||||
output: null,
|
||||
exitCode: null,
|
||||
durationMs: null,
|
||||
});
|
||||
|
||||
const databaseWithPolicies = await dbClient.query.database.findFirst({
|
||||
where: eq(drizzleDb.schemas.database.id, databaseId),
|
||||
with: {alertPolicies: true},
|
||||
});
|
||||
|
||||
if (databaseWithPolicies) {
|
||||
await sendNotificationsBackupRestore(databaseWithPolicies, "error_restore");
|
||||
}
|
||||
} catch (err) {
|
||||
log.error({error: err, name: "handleFailedRestoration"}, "Failed to record restoration failure job log / notification");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user